Toshimaru's Blog

Run and Connect to MySQL on Docker

I wanted to run MySQL 8.0.x on docker aside from MySQL 5.7 running on my localhost, so I’ll give a instruction for it.

docker pull

First of all, let’s run docker pull.

$ docker pull mysql:8.0

(8.0 means a tag. if it’s not specified, latest mysql docker image is used.)

docker run

Then, run docker run.

$ docker run --name mysql -e MYSQL_ROOT_PASSWORD=xxxx -p 3306:3306 mysql:8.0

MYSQL_ROOT_PASSWORD is required, you can set whatever password you like.

Connect to MySQL

Finally, let’s conect to MySQL run by docker.

$ mysql -h -u root -p
Enter password:
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/Cellar/mysql/5.7.22/lib/plugin/, 2): image not found

But we’ve got an error. This is because mysql server version and client version are different and those encryption methods are different.

Let’s connect to mysql on docker.

# from localhost
$ docker exec -it mysql bash 

# inside docker
# mysql -uroot -p 
Enter password:

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


It works!