@[TOC]
安装docker
[root@VM-8-9-centos app]# yum -y install docker
启动docker服务
[root@VM-8-9-centos app]# systemctl start docker
查看服务状态
[root@VM-8-9-centos app]# systemctl status docker
设置为开机自启动
[root@VM-8-9-centos app]# systemctl enable docker
查看mysql镜像
[root@VM-8-9-centos app]# docker search mysql
拉取mysql镜像
[root@VM-8-9-centos app]# docker pull mysql
查看mysql镜像
[root@VM-8-9-centos app]# docker images -a
建立mysql相关目录
[root@VM-8-9-centos app]# mkdir -p /opt/mysql
进入新建的mysql目录
[root@VM-8-9-centos mysql]# cd /opt/mysql/
[root@VM-8-9-centos mysql]# echo $PWD
/opt/mysql
启动mysql容器
[root@VM-8-9-centos mysql]# docker run --name mysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d -i -p 3306:3306 mysql:latest
容器在/var/lib/docker/containers/
下
查看mysql进程
[root@VM-8-9-centos containers]# docker ps -a
docker exec -it 7a8886e3d43f bash
root@7a8886e3d43f:/# mysql -uroot -p'123456'
新建admin用户并开启远程访问
mysql> create user 'admin'@'%' identified by '123456';
Query OK, 0 rows affected (0.02 sec)
mysql> ALTER USER 'admin'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to 'admin'@'%' with grant option;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | admin | mysql_native_password |
| % | root | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | caching_sha2_password |
+-----------+------------------+-----------------------+
6 rows in set (0.00 sec)
安全组开启3306端口访问权限
登录腾讯云控制台选择安全组-添加规则-添加入站规则(如下图)
如果服务器为轻量级服务器,就得添加防火墙配置
使用Navicat连接mysql
新建一个mysql连接,输入对应信息后点击连接测试
码字不易,感谢支持!