同前文用龙芯+麒麟+docker快速搭建nginx-CSDN博客,一样利用Quay下载mysql的image,地址这里:Quay,我选择了同事推荐的8.0.23版本,下载后配置代码如下:
[root@localhost ~]#docker run --name mysql -p 3306:3306 -v ~/mysql/date:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password -d cr.loongnix.cn/library/mysql:8.0.23
--name:容器名字
-p:映射端口
-v:数据挂载卷位置(‘~’这个代表在目前目录下)
-e MYSQL_ROOT_PASSWORD=password:设置root密码
-d:保持后台运行
创建容器后,立刻运行一下mysql客户端
[root@localhost ~]# mysql -hx.x.x.x -p3306 -uroot -ppassword
出现错误信息
ERROR 2059 (HY000): Plugin caching_sha2_password could not be loaded: /usr/lib64/mariadb/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
参考https://www.cnblogs.com/Xinenhui/p/15179650.html解决方案,进入容器内处理
[root@localhost ~]# docker exec -it mysql bash root@9995d5dfbb85:/# mysql -u root -p mysql> select @@version; mysql> show variables like 'default_authentication_plugin'; mysql> select host,user,plugin from mysql.user; mysql> ALTER USER 'testuser'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
退出容器,重新运行mysql客户端
[root@localhost ~]# mysql -hx.x.x.x -p3306 -utestuser -p123456
再度报错ERROR 1045 (28000): Access denied for user 'testuser'@'172.17.0.1' (using password: YES)
确认密码没有问题,想起是否有客户地址限制,查了一下网上资料,参考ERROR 1045 (28000): Access denied for user ‘root‘@‘172.17.0.1‘ (using password: YES)_access denied for user 'root'@'172.17.0.1' (using -CSDN博客再次进入容器输入以下代码
mysql>CREATE USER 'testuser2'@'%' IDENTIFIED BY '123456'; mysql>ALTER USER 'testuser2'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; mysql>GRANT ALL PRIVILEGES ON *.* TO 'testuser2'@'%'; mysql>flush privileges;
GRANT 语句为了提升testuser2的权限范围,退出容器,在宿主机输入
mysql -hx.x.x.x -p3306 -utestuser2 -p123456
顺利进入mysql的光标。