MySQL 8.0.x in Docker with mysql or mysql2 package fails with ER_ACCESS_DENIED_ERROR

  docker, javascript, mysql, node.js

I’ve found some posts on this but nothing seems to work. I’m simply firing up MySQL 8.0 in a docker container:

docker run --rm -v /local/path/mysql/8.0:/var/lib/mysql -p 3306:3306 --name mysql-local -e MYSQL_ROOT_PASSWORD=pass123 -d mysql:8.0

I can connect in DataGrip and see users:

enter image description here

However, using either the mysql or mysql2 packages, I’m unable to connect with the root user or a user I create. I always get:

code: ‘ER_ACCESS_DENIED_ERROR’, errno: 1045, sqlMessage: "Access
denied for user ”@’172.17.0.1′ (using password: NO)", sqlState:
‘28000’, fatal: true

I want this, as I’m going to be executing scripts to build the database, tables, etc.:

const connection = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "pass123"
});

I’ve tried creating the db and connecting as well, like so, but nothing changes:

const connection = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "pass123",
    database: "testdb"
});

I’ve tried altering the root user like so, but that also changes nothing:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'pass123';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';
FLUSH PRIVILEGES;

I do see this in the console though, when firing the lines above:

information_schema> ALTER USER ‘root’@’localhost’ IDENTIFIED WITH
mysql_native_password BY ‘pass123’ [2021-02-25 08:49:29] completed in
15 ms information_schema> GRANT ALL PRIVILEGES ON . TO
‘root’@’localhost’ [2021-02-25 08:49:45] [HY000][1285] MySQL is
started in –skip-name-resolve mode; you must restart it without this
switch for this grant to work

What’s the trick? Never had this problem with the 5.7 container.

Source: Docker Questions

LEAVE A COMMENT