1、mysql版本就选择5.7吧
docker pull mysql:5.7 #拉取镜像
docker run -id --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7 #启动容器,root密码是必须指定的
2、在宿主机安装mysql-client客户端
rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps #卸载mariadb数据库
yum -y install https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-community-common-5.7.37-1.el7.x86_64.rpm
yum -y install https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-community-libs-5.7.37-1.el7.x86_64.rpm
yum -y install https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-community-client-5.7.37-1.el7.x86_64.rpm
3、连接数据库
mysql -uroot -p123456 -h127.0.0.1 #必须指定主机名不能无法连接