使用Docker部署MySQL作为测试环境
这里说明了作为测试环境,生产环境下不建议将MySQL使用Docker部署
查找镜像
root@centos7-docker opt]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 12527 [OK]
mariadb MariaDB Server is a high performing open sou… 4819 [OK]
percona Percona Server is a fork of the MySQL relati… 575 [OK]
phpmyadmin phpMyAdmin - A web interface for MySQL and M… 527 [OK]
bitnami/mysql Bitnami MySQL Docker Image 70 [OK]
linuxserver/mysql-workbench 36
linuxserver/mysql A Mysql container, brought to you by LinuxSe… 35
ubuntu/mysql MySQL open source fast, stable, multi-thread… 31
circleci/mysql MySQL is a widely used, open-source relation… 25
google/mysql MySQL server for Google Compute Engine 21 [OK]
vmware/harbor-db Mysql container for Harbor 10
bitnami/mysqld-exporter 3
ibmcom/mysql-s390x Docker image for mysql-s390x 2
newrelic/mysql-plugin New Relic Plugin for monitoring MySQL databa… 1 [OK]
vitess/mysqlctld vitess/mysqlctld 1 [OK]
nasqueron/mysql 1 [OK]
cimg/mysql 0
silintl/mysql-backup-restore Simple docker image to perform mysql backups… 0 [OK]
drud/mysql-local-57 ddev mysql local container 0
drud/mysql 0
drud/mysql-docker-local-57 This repo has been deprecated, new tags are … 0
drud/mysql-docker-local docker containers for local womysql rk 0 [OK]
docksal/mysql MySQL service images for Docksal - https://d… 0
mirantis/mysql 0
drud/mysqld-exporter 0
建立目录映射
mkdir -p /opt/docker/mysql
mkdir -p /opt/docker/mysql/logs
mkdir -p /opt/docker/mysql/data
mkdir -p /opt/docker/mysql/mysql-files
运行
docker run -p 3306:3306 --name mysql-3306 \
-v /opt/docker/mysql/conf:/etc/mysql \
-v /opt/docker/mysql/logs:/var/log/mysql \
-v /opt/docker/mysql/data:/var/lib/mysql \
-v /opt/docker/mysql/mysql-files:/var/lib/mysql-files/ \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql
修改可以远程连接
进入容器
docker exec -it mysql-3306 /bin/bash
登录mysql
mysql -u root -P 123456
授权
mysql> use mysql;
Database changed
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> GRANT ALL ON *.* TO 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT ALL ON *.* TO 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
如果使用Navicat的话。 因为Navicat只支持旧版本的加密,需要更改mysql的加密规则
ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;