Below are a few thoughts and notes on using MySQL with TypeORM.
mysql --version
it likely means you do not have mysql added to your $PATH. Check this by: echo $PATH
export path=$PATH:/usr/local/mysql/bin
mysql -h hostNameGoesHere -u usernameGoesHere -p
mysql -h hostNameGoesHere -u usernameGoesHere -p databaseNameGoesHere
If you run into the following error when trying to connect to MySQL from TypeORM:
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
The reason this happens is explained in detail here, but in short, MySQL 8.0.4 introduced a new default authentication mechanism 'cachingsha2pasword'. This is more secure than the previous method used by MySQL, which is 'mysqlnativepassword'. Now, TypeORM, under the hood, uses mysqljs (I think). Work is being done in order to support this new authentication, however, as of writing, it has not been merged into master. As such, in order to get around this, on MySQL, you need to do the following:
ALTER USER 'userName'@'hostName' IDENTIFIED WITH mysql_native_password BY 'passwordHere';
SELECT plugin FROM mysql.user WHERE User = 'root';
Thereafter, you need to run (from the MySQL terminal):
FLUSH PRIVILEGES;
quit
You should not be able to run TypeORM again and hopefully it will connect. If not, you may find some guidance by reviewing the following:
Ultimately, I dug into all of the above in order to add a MySQL database to my Itemly API. The work-in-progress code is here.