Centos 上安装 Docker
sudo yum -y install docker
启动 docker
service docker start
安装 Mysql
docker pull mysql:5.7
运行Mysql
sudo docker run --name pwc-mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql
配置Mysql
这是远程链接 mysql 连不上,需要进行配置 bind ip
需要进入 docker 的命令行中修改,把 bind-address 改成 0.0.0.0
sudo docker exec -it 342d7aaa66f7 /bin/bash
重启某个镜像
docker restart 342d7aaa66f7
vim /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
bind-address = 0.0.0.0
然后再通过远程客户端可以登录mysql 了
Mysql 修改密码
mysql -u root
mysql> SET PASSWORD FOR ('root'@'%') = PASSWORD('password');
Mysql 好用的客户端 mysli
sudo pip install mycli