考虑到实际情况需要经常使用MySQL,为了方便大家能够快速基于Docker搭建MySQL这里以Linux下为例
进行说明,对于Windows用户来说直接通过查看官网Hub即可。
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum install net-tool -y
yum install chrony -y
sed -i "/server/d" /etc/chrony.conf
vi /etc/chrony.conf 增加 server ntp.aliyun.com iburst
systemctl restart chronyd
chronyc tracking
hostnamectl set-hostname mysqlServer
systemctl stop firewalld
systemctl disable firewalld
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io
sudo systemctl enable docker
mkdir /etc/docker
vi /etc/docker/daemon.json 添加如下内容
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
sudo systemctl restart docker
docker pull mysql:5.7.28
mkdir /home/mysql
docker run -d -p 3306:3306 -v /home/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=** --name mysql --restart=always mysql:5.7.28
docker exec -it [containerId] bash
# 进入后通过 mysql -u root -p进去并执行以下语句
grant all privileges on *.* to root@"%" identified by "password" with grant option;
flush privileges;
原文:https://www.cnblogs.com/yaozhenfa/p/13679902.html