Docker 安装Mysql
Docker安装Mysql5.6
- 下载mysql的镜像
- git pull mysql:5.6
- 创建mysql的挂载目录
mkdir -p /usr/local/docker/mysql/data /usr/local/docker/mysql/logs /usr/local/docker/mysql/conf
- 创建配置文件
touch /usr/local/docker/mysql/conf/my.cnf
- 创建容器,将数据,日志,配置文件映射到本机
docker run -p 3306:3306 --name mymysql \ -v /usr/local/docker/mysql/conf:/etc/mysql/conf.d \ -v /usr/local/docker/mysql/logs:/logs \ -v /usr/local/docker/mysql/data:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=root \ -d mysql:5.6
- 查询日志情况
docker logs mymysql
- 查看容器
docker ps
- 开启远程访问权限
docker exec -it mymysql bash
use mysql; select host,user from user; update user set host='%' where user='root'; flush privileges;
- 查看防火墙
- systemctl status firewalld
- 开启防火墙
- systemctl start firewalld
- 添加端口
- firewall-cmd --zone=public --add-port=3306/tcp --permanent
- 刷新重置
- firewall-cmd --reload
- 将docker设置成开机自启动
- systemctl enable docker
- myredis容器设置成随服务启
- docker update --restart =always mymysql