# docker pull mysql:8 # mkdir -p /mysql/{datadir,etc/mysql} # cat >/mysql/etc/mysql/my.cnf <<EOF [mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql secure-file-priv= NULL symbolic-links=0 default_authentication_plugin=mysql_native_password EOF # docker run -d --name mysql -v /mysql/datadir:/var/lib/mysql -v /mysql/etc/mysql/my.cnf:/etc/mysql/my.cnf -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:8
使用mysql客户端连接提示: cannot be loaded: /usr/lib/x86_64-linux-gnu/mariadb18/plugin/caching_sha2_password.so
解决办法,执行:
# docker exec -it mysql /bin/sh # mysql -uroot -p mysql> use mysql mysql> alter user 'root'@'%' identified by 'password' password expire never; mysql> alter user 'root'@'%' identified with mysql_native_password by '123456'; mysql> flush privileges;
再次登录,就正常了:
mysql -uroot -h127.0.0.1 -p123456