Setup
- Expressjs (Node) running in at localhost:3000 on a Windows 10 PC.
- MySQL ran in a Docker container at 192.168.99.100:3306 via docker-machine.
Problem
When trying to connect server to MySQL using:
const connection = mysql.createConnection({
host: '192.168.99.100',
user: 'root',
password: 'foo123',
database: 'foo_db'
});
Getting:
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgr ading MySQL client
Checked many answer here at StackOverflow. Most of them use (example):
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'MyNewPass';
However I get:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'MyNewPass'; Query OK, 0 rows affected (0.06 sec)
And the server still doesn't want to connect. Using MySQL 5.7 works fine.
Any ideas how to fix this for MySQL 8?
ADDED:
Just to be crystal clear:
- Using official MySQL Docker: https://hub.docker.com/_/mysql/.
- server.js gist: https://gist.github.com/h3d0/8d021d25892f34976d806485f18479f2
- Running MySQL Docker gist: https://gist.github.com/h3d0/505f41a633f571e12117b32638035412
- Connection to MySQL Docker gist: https://gist.github.com/h3d0/aea7b48144d08403d69e2da3ccdcdde7
After connecting to MySQL, running:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'foo123';
FLUSH PRIVILEGES;
Restarting Node.js and MySQL container and nothing happens.