1、容器环境
[root@zlm ~]# docker -v
Docker version 26.1.4, build 5650f9b
2、本地映射文件
mkdir /data/dockerData/mysql/conf data log
3、命令启动
docker run -p 3306:3306 --name mysql -v /data/dockerData/mysql/log:/var/log/mysql -v /data/dockerData/mysql/data:/var/lib/mysql -v /data/dockerData/mysql/conf:/etc/mysql/conf.d --restart=always -e MYSQL_ROOT_PASSWORD=123456 -d swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/mysql:5.7.44
4、进入容器
docker exec mysql -it /bin/bash
5、开启远程访问权限
命令:use mysql;
命令:select host,user from user;
命令:ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
命令:flush privileges;
把root用户的密码改成 mysql_native_password 模式,即可远程连接
#创建一个账号-admin,用来进行远程访问;
CREATE USER 'admin'@'%' IDENTIFIED BY '123456';
赋予所有权限给之前创建的账号:admin
GRANT ALL ON *.* TO 'admin'@'%';
确认使用密码{123456}登录此账号{admin}
密码尽量复杂,安全性更高。
ALTER USER 'admin'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
刷新权限
FLUSH PRIVILEGES;