docker部署MySQL5.7设置密码和远程访问的方法

运行MySQL

docker run -p 3306:3306 --name mysql57 -v /root/mysql/log:/var/log/mysql -v /root/mysql/data:/var/lib/mysql -v /root/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=D7txumqc2b! -d mysql:5.7 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

查看容器的IP地址
docker inspect 容器ID |grep IPAdress
进入MySQL容器
docker exec -it mysql57 bash
设置密码和授权
mysql -u root -p
mysql5.7及以后
use mysql
update user set authentication_string=password("123456") where user="root";
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;

FLUSH PRIVILEGES;

你可能感兴趣的:(docker,容器,运维)