MySQL Docker安装
docker 安装
Linux
sudo docker run -p 3306:3306 --name mysql \
-v /usr/local/docker/mysql/conf:/etc/mysql \
-v /usr/local/docker/mysql/logs:/var/log/mysql \
-v /usr/local/docker/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:5.7
Windows
docker run -p 3306:3306 --name mysql -v d:/mysql/conf:/etc/mysql -v d:/mysql/logs:/var/log/mysql -v d:/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
检查容器是否正确运行
docker container ls
进入容器
sudo docker exec -it mysql bash
mysql -uroot -p123456
关闭防火墙
# 开放端口:
$ systemctl status firewalld
$ firewall-cmd --zone=public --add-port=3306/tcp -permanent
$ firewall-cmd --reload
# 关闭防火墙:
$ sudo systemctl stop firewalld
修改访问权限
$ sudo docker exec -it mysql bash
$ mysql -uroot -p123456
mysql> grant all privileges on *.* to root@'%' identified by "password";