查看源图像
1.Docker安装mysql和修改root用户密码
====移除container
docker rm MysqlContainerId
docker rmi MysqlImageId
====安装mysql
sudo docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:latest
=====查看container
docker ps -a
=====查看image
docker images
=====启动mysql
docker start mysql
=====进入mysql
docker exec -it mysql bash
mysql -u root -p
select user,host,authentication_string,plugin from mysql.user;
=====修改root用户密码和加密方式
ALTER USER 'root'@'localhost' IDENTIFIED BY 123456789' PASSWORD EXPIRE NEVER;
alter user 'root'@'%' identified with mysql_native_password by '123456789';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 123456789';
=====刷新权限
flush privileges;
=====退出
exit
====重启mysql容器
docker restart mysql
2.查看端口和重启防火墙
====查看开放端口
netstat -talnp
====关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
====防火墙状态
systemctl status firewalld
====开启防火墙
systemctl start firewalld
命令后出现Failed to start firewalld.service: Unit is masked
执行命令,即可实现取消服务的锁定
# systemctl unmask firewalld
下次需要锁定该服务时执行
# systemctl mask firewalld
====查询端口开放状态
firewall-cmd --query-port =3306/tcp
3.Navicat重新连接mysql
===查看mysql服务运行状态
ps -ef | grep mysqld
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码' PASSWORD EXPIRE NEVER;
alter user 'root'@'%' identified with mysql_native_password by '你的密码';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';