官方镜像
https://hub.docker.com/_/mysql
http://hub.daocloud.io
代码语言:javascript复制5.1、5.5、5.6、5.7 、 8.0 、 8.4 都是LTS(Long Term Support,长期支持版本)
# registry.cn-hangzhou.aliyuncs.com/lhrbest/
docker search mysql
nohup docker pull mysql:5.5.62 &
nohup docker pull mysql:5.6.51 &
nohup docker pull mysql:5.7.44 &
nohup docker pull mysql:8.0.37 &
nohup docker pull mysql:8.4.0 &
docker rm mysql55 -f
docker rm mysql56 -f
docker rm mysql57 -f
docker rm mysql80 -f
docker rm mysql84 -f
mkdir -p /etc/mysql/mysql55/conf
mkdir -p /etc/mysql/mysql56/conf
mkdir -p /etc/mysql/mysql57/conf
mkdir -p /etc/mysql/mysql80/conf
mkdir -p /etc/mysql/mysql84/conf
cat > /etc/mysql/mysql55/conf/my.cnf <<"EOF"
[mysqld]
skip-name-resolve
log-bin
server_id=553415
character_set_server=utf8mb4
EOF
cat > /etc/mysql/mysql56/conf/my.cnf <<"EOF"
[mysqld]
skip-name-resolve
log-bin
server_id=563416
character_set_server=utf8mb4
EOF
cat > /etc/mysql/mysql57/conf/my.cnf <<"EOF"
[mysqld]
default-time-zone = ' 8:00'
log_timestamps = SYSTEM
skip-name-resolve
log-bin
server_id=573417
character_set_server=utf8mb4
EOF
cat > /etc/mysql/mysql80/conf/my.cnf <<"EOF"
[mysqld]
default-time-zone = ' 8:00'
log_timestamps = SYSTEM
skip-name-resolve
log-bin
server_id=803418
character_set_server=utf8mb4
default_authentication_plugin=mysql_native_password
EOF
cat > /etc/mysql/mysql84/conf/my.cnf <<"EOF"
[mysqld]
default-time-zone = ' 8:00'
log_timestamps = SYSTEM
skip-name-resolve
log-bin
server_id=843419
character_set_server=utf8mb4
mysql_native_password=on
EOF
docker run -d --name mysql55 -h mysql55 -p 3415:3306
-v /etc/mysql/mysql55/conf:/etc/mysql/conf.d
-e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai
mysql:5.5.62
docker run -d --name mysql56 -h mysql56 -p 3416:3306
-v /etc/mysql/mysql56/conf:/etc/mysql/conf.d
-e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai
mysql:5.6.51
docker run -d --name mysql57 -h mysql57 -p 3417:3306
-v /etc/mysql/mysql57/conf:/etc/mysql/conf.d
-e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai
mysql:5.7.44
docker run -d --name mysql80 -h mysql80 -p 3418:3306
-v /etc/mysql/mysql80/conf:/etc/mysql/conf.d
-e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai
mysql:8.0.37
docker run -d --name mysql84 -h mysql84 -p 3419:3306
-v /etc/mysql/mysql84/conf:/etc/mysql/conf.d
-e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai
mysql:8.4.0
docker logs -f mysql55
docker logs -f mysql56
docker logs -f mysql57
docker logs -f mysql80
docker logs -f mysql84
mysql -uroot -plhr -h127.0.0.1 -P3415 -e "select now(),@@hostname,@@version;"
mysql -uroot -plhr -h127.0.0.1 -P3416 -e "select now(),@@hostname,@@version;"
mysql -uroot -plhr -h127.0.0.1 -P3417 -e "select now(),@@hostname,@@version;"
mysql -uroot -plhr -h127.0.0.1 -P3418 -e "select now(),@@hostname,@@version;"
mysql -uroot -plhr -h127.0.0.1 -P3419 -e "select now(),@@hostname,@@version;"
docker restart mysql55 mysql56 mysql57 mysql80 mysql84
检查版本
代码语言:javascript复制[root@lhrdb ~]# mysql -uroot -plhr -h127.0.0.1 -P3415 -e "select now(),@@hostname,@@version;"
--------------------- ------------ ------------
| now() | @@hostname | @@version |
--------------------- ------------ ------------
| 2023-08-21 12:35:29 | mysql55 | 5.5.62-log |
--------------------- ------------ ------------
[root@lhrdb ~]# mysql -uroot -plhr -h127.0.0.1 -P3416 -e "select now(),@@hostname,@@version;"
--------------------- ------------ ------------
| now() | @@hostname | @@version |
--------------------- ------------ ------------
| 2023-08-21 12:35:29 | mysql56 | 5.6.51-log |
--------------------- ------------ ------------
[root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3417 -e "select now(),@@hostname,@@version;"
--------------------- ------------ ------------
| now() | @@hostname | @@version |
--------------------- ------------ ------------
| 2024-05-09 09:14:24 | mysql57 | 5.7.44-log |
--------------------- ------------ ------------
[root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3418 -e "select now(),@@hostname,@@version;"
--------------------- ------------ -----------
| now() | @@hostname | @@version |
--------------------- ------------ -----------
| 2024-05-09 09:14:26 | mysql80 | 8.0.37 |
--------------------- ------------ -----------
[root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3419 -e "select now(),@@hostname,@@version;"
--------------------- ------------ -----------
| now() | @@hostname | @@version |
--------------------- ------------ -----------
| 2024-05-09 09:09:46 | mysql84 | 8.4.0 |
--------------------- ------------ -----------
示例
代码语言:javascript复制root@lhrxxt:~# docker run -d --name mysql8030 -h mysql8030 -p 3418:3306
> -v /etc/mysql/mysql8030/conf:/etc/mysql/conf.d
> -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai
> mysql:8.0.30
f6e94a91fd69e26d0e9e7bd5b4ef11ecde0f4b8502299c537342141ea01bf80a
root@lhrxxt:~#
root@lhrxxt:~# cat > /etc/mysql/mysql8030/conf/my.cnf <<"EOF"
> [mysqld]
> default-time-zone = ' 8:00'
> log_timestamps = SYSTEM
> skip-name-resolve
> log-bin
> server_id=80303418
> character_set_server=utf8mb4
> EOF
root@lhrxxt:~# docker restart mysql8030
mysql8030
root@lhrxxt:~# docker exec -it mysql8030 bash
bash-4.4# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
bash-4.4# mysql -uroot -plhr
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 9
Server version: 8.0.30 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> show databases;
--------------------
| Database |
--------------------
| information_schema |
| mysql |
| performance_schema |
| sys |
--------------------
4 rows in set (0.05 sec)
mysql> create database lhrdb;
Query OK, 1 row affected (0.04 sec)
mysql> show databases;
--------------------
| Database |
--------------------
| information_schema |
| lhrdb |
| mysql |
| performance_schema |
| sys |
--------------------
5 rows in set (0.00 sec)
麦老师镜像
代码语言:javascript复制docker rm -f lhrmysqlall
docker run -d --name lhrmysqlall -h lhrmysqlall
-p 13306-13406:13306-13406 -p 222:22
-v /sys/fs/cgroup:/sys/fs/cgroup
--privileged=true
lhrbest/lhrmysqlall:2.0 /usr/sbin/init
docker exec -it lhrmysqlall bash
mysqld_multi report
示例:
代码语言:javascript复制[root@lhrmysqlall /]# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld556213321 is not running
MySQL server from group: mysqld564813331 is not running
MySQL server from group: mysqld573013341 is not running
MySQL server from group: mysqld801913380 is not running
MySQL server from group: mysqld810 is not running
[root@lhrmysqlall /]# mysqld_multi start
[root@lhrmysqlall /]# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld556213321 is running
MySQL server from group: mysqld564813331 is running
MySQL server from group: mysqld573013341 is running
MySQL server from group: mysqld801913380 is running
MySQL server from group: mysqld810 is running
[root@lhrmysqlall /]# ps -ef|grep mysql
root 236 0 0 16:08 pts/0 00:00:00 /bin/sh /usr/local/mysqlsoft/5.5.62/bin/mysqld_safe --port=13321 --basedir=/usr/local/mysqlsoft/5.5.62 --datadir=/usr/local/mysqldata/data556213321 --socket=/tmp/mysqls556213321.sock --server_id=556213321 --log-bin --skip-name-resolve --character_set_server=utf8mb4
root 246 0 0 16:08 pts/0 00:00:00 /bin/sh /usr/local/mysqlsoft/5.6.48/bin/mysqld_safe --port=13331 --basedir=/usr/local/mysqlsoft/5.6.48 --datadir=/usr/local/mysqldata/data564813331 --socket=/tmp/mysqls56483331.sock --server_id=564813331 --log-bin --skip-name-resolve --character_set_server=utf8mb4
root 262 0 0 16:08 pts/0 00:00:00 /bin/sh /usr/local/mysqlsoft/5.7.30/bin/mysqld_safe --port=13341 --basedir=/usr/local/mysqlsoft/5.7.30 --datadir=/usr/local/mysqldata/data573013341 --socket=/tmp/mysqls57303341.sock --server_id=573013341 --log-bin --default-time-zone= 8:00 --log_timestamps=SYSTEM --skip-name-resolve --character_set_server=utf8mb4
root 285 0 0 16:08 pts/0 00:00:00 /bin/sh /usr/local/mysqlsoft/8.0.19/bin/mysqld_safe --port=13380 --basedir=/usr/local/mysqlsoft/8.0.19 --datadir=/usr/local/mysqldata/data801913380 --socket=/tmp/mysqls801913380.sock --default_authentication_plugin=mysql_native_password --server_id=801913380 --log-bin --default-time-zone= 8:00 --log_timestamps=SYSTEM --skip-name-resolve --character_set_server=utf8mb4
root 314 0 0 16:08 pts/0 00:00:00 /bin/sh /usr/local/mysqlsoft/8.1.0/bin/mysqld_safe --port=13381 --basedir=/usr/local/mysqlsoft/8.1.0 --datadir=/usr/local/mysqldata/data810 --socket=/tmp/mysqls810.sock --default_authentication_plugin=mysql_native_password --server_id=801913381 --log-bin --default-time-zone= 8:00 --log_timestamps=SYSTEM --skip-name-resolve --character_set_server=utf8mb4
mysql 1080 236 0 16:08 pts/0 00:00:00 /usr/local/mysqlsoft/5.5.62/bin/mysqld --basedir=/usr/local/mysqlsoft/5.5.62 --datadir=/usr/local/mysqldata/data556213321 --plugin-dir=/usr/local/mysqlsoft/5.5.62/lib/plugin --user=mysql --server-id=556213321 --log-bin --skip-name-resolve --character-set-server=utf8mb4 --log-error=lhrmysqlall.err --pid-file=lhrmysqlall.pid --socket=/tmp/mysqls556213321.sock --port=13321
mysql 1143 246 2 16:08 pts/0 00:00:00 /usr/local/mysqlsoft/5.6.48/bin/mysqld --basedir=/usr/local/mysqlsoft/5.6.48 --datadir=/usr/local/mysqldata/data564813331 --plugin-dir=/usr/local/mysqlsoft/5.6.48/lib/plugin --user=mysql --server-id=564813331 --log-bin --skip-name-resolve --character-set-server=utf8mb4 --log-error=lhrmysqlall.err --pid-file=lhrmysqlall.pid --socket=/tmp/mysqls56483331.sock --port=13331
mysql 1221 262 2 16:08 pts/0 00:00:00 /usr/local/mysqlsoft/5.7.30/bin/mysqld --basedir=/usr/local/mysqlsoft/5.7.30 --datadir=/usr/local/mysqldata/data573013341 --plugin-dir=/usr/local/mysqlsoft/5.7.30/lib/plugin --user=mysql --server-id=573013341 --log-bin --default-time-zone= 8:00 --log-timestamps=SYSTEM --skip-name-resolve --character-set-server=utf8mb4 --log-error=lhrmysqlall.err --pid-file=lhrmysqlall.pid --socket=/tmp/mysqls57303341.sock --port=13341
mysql 1269 285 4 16:08 pts/0 00:00:00 /usr/local/mysqlsoft/8.0.19/bin/mysqld --basedir=/usr/local/mysqlsoft/8.0.19 --datadir=/usr/local/mysqldata/data801913380 --plugin-dir=/usr/local/mysqlsoft/8.0.19/lib/plugin --user=mysql --default-authentication-plugin=mysql_native_password --server-id=801913380 --log-bin --default-time-zone= 8:00 --log-timestamps=SYSTEM --skip-name-resolve --character-set-server=utf8mb4 --log-error=lhrmysqlall.err --pid-file=lhrmysqlall.pid --socket=/tmp/mysqls801913380.sock --port=13380
mysql 1276 314 4 16:08 pts/0 00:00:00 /usr/local/mysqlsoft/8.1.0/bin/mysqld --basedir=/usr/local/mysqlsoft/8.1.0 --datadir=/usr/local/mysqldata/data810 --plugin-dir=/usr/local/mysqlsoft/8.1.0/lib/plugin --user=mysql --default-authentication-plugin=mysql_native_password --server-id=801913381 --log-bin --default-time-zone= 8:00 --log-timestamps=SYSTEM --skip-name-resolve --character-set-server=utf8mb4 --log-error=lhrmysqlall.err --pid-file=lhrmysqlall.pid --socket=/tmp/mysqls810.sock --port=13381
root 1495 64 0 16:09 pts/0 00:00:00 grep --color=auto mysql
[root@lhrmysqlall /]# ps -ef|grep mysqld
root 236 0 0 16:08 pts/0 00:00:00 /bin/sh /usr/local/mysqlsoft/5.5.62/bin/mysqld_safe --port=13321 --basedir=/usr/local/mysqlsoft/5.5.62 --datadir=/usr/local/mysqldata/data556213321 --socket=/tmp/mysqls556213321.sock --server_id=556213321 --log-bin --skip-name-resolve --character_set_server=utf8mb4
root 246 0 0 16:08 pts/0 00:00:00 /bin/sh /usr/local/mysqlsoft/5.6.48/bin/mysqld_safe --port=13331 --basedir=/usr/local/mysqlsoft/5.6.48 --datadir=/usr/local/mysqldata/data564813331 --socket=/tmp/mysqls56483331.sock --server_id=564813331 --log-bin --skip-name-resolve --character_set_server=utf8mb4
root 262 0 0 16:08 pts/0 00:00:00 /bin/sh /usr/local/mysqlsoft/5.7.30/bin/mysqld_safe --port=13341 --basedir=/usr/local/mysqlsoft/5.7.30 --datadir=/usr/local/mysqldata/data573013341 --socket=/tmp/mysqls57303341.sock --server_id=573013341 --log-bin --default-time-zone= 8:00 --log_timestamps=SYSTEM --skip-name-resolve --character_set_server=utf8mb4
root 285 0 0 16:08 pts/0 00:00:00 /bin/sh /usr/local/mysqlsoft/8.0.19/bin/mysqld_safe --port=13380 --basedir=/usr/local/mysqlsoft/8.0.19 --datadir=/usr/local/mysqldata/data801913380 --socket=/tmp/mysqls801913380.sock --default_authentication_plugin=mysql_native_password --server_id=801913380 --log-bin --default-time-zone= 8:00 --log_timestamps=SYSTEM --skip-name-resolve --character_set_server=utf8mb4
root 314 0 0 16:08 pts/0 00:00:00 /bin/sh /usr/local/mysqlsoft/8.1.0/bin/mysqld_safe --port=13381 --basedir=/usr/local/mysqlsoft/8.1.0 --datadir=/usr/local/mysqldata/data810 --socket=/tmp/mysqls810.sock --default_authentication_plugin=mysql_native_password --server_id=801913381 --log-bin --default-time-zone= 8:00 --log_timestamps=SYSTEM --skip-name-resolve --character_set_server=utf8mb4
mysql 1080 236 0 16:08 pts/0 00:00:00 /usr/local/mysqlsoft/5.5.62/bin/mysqld --basedir=/usr/local/mysqlsoft/5.5.62 --datadir=/usr/local/mysqldata/data556213321 --plugin-dir=/usr/local/mysqlsoft/5.5.62/lib/plugin --user=mysql --server-id=556213321 --log-bin --skip-name-resolve --character-set-server=utf8mb4 --log-error=lhrmysqlall.err --pid-file=lhrmysqlall.pid --socket=/tmp/mysqls556213321.sock --port=13321
mysql 1143 246 2 16:08 pts/0 00:00:00 /usr/local/mysqlsoft/5.6.48/bin/mysqld --basedir=/usr/local/mysqlsoft/5.6.48 --datadir=/usr/local/mysqldata/data564813331 --plugin-dir=/usr/local/mysqlsoft/5.6.48/lib/plugin --user=mysql --server-id=564813331 --log-bin --skip-name-resolve --character-set-server=utf8mb4 --log-error=lhrmysqlall.err --pid-file=lhrmysqlall.pid --socket=/tmp/mysqls56483331.sock --port=13331
mysql 1221 262 1 16:08 pts/0 00:00:00 /usr/local/mysqlsoft/5.7.30/bin/mysqld --basedir=/usr/local/mysqlsoft/5.7.30 --datadir=/usr/local/mysqldata/data573013341 --plugin-dir=/usr/local/mysqlsoft/5.7.30/lib/plugin --user=mysql --server-id=573013341 --log-bin --default-time-zone= 8:00 --log-timestamps=SYSTEM --skip-name-resolve --character-set-server=utf8mb4 --log-error=lhrmysqlall.err --pid-file=lhrmysqlall.pid --socket=/tmp/mysqls57303341.sock --port=13341
mysql 1269 285 3 16:08 pts/0 00:00:00 /usr/local/mysqlsoft/8.0.19/bin/mysqld --basedir=/usr/local/mysqlsoft/8.0.19 --datadir=/usr/local/mysqldata/data801913380 --plugin-dir=/usr/local/mysqlsoft/8.0.19/lib/plugin --user=mysql --default-authentication-plugin=mysql_native_password --server-id=801913380 --log-bin --default-time-zone= 8:00 --log-timestamps=SYSTEM --skip-name-resolve --character-set-server=utf8mb4 --log-error=lhrmysqlall.err --pid-file=lhrmysqlall.pid --socket=/tmp/mysqls801913380.sock --port=13380
mysql 1276 314 4 16:08 pts/0 00:00:00 /usr/local/mysqlsoft/8.1.0/bin/mysqld --basedir=/usr/local/mysqlsoft/8.1.0 --datadir=/usr/local/mysqldata/data810 --plugin-dir=/usr/local/mysqlsoft/8.1.0/lib/plugin --user=mysql --default-authentication-plugin=mysql_native_password --server-id=801913381 --log-bin --default-time-zone= 8:00 --log-timestamps=SYSTEM --skip-name-resolve --character-set-server=utf8mb4 --log-error=lhrmysqlall.err --pid-file=lhrmysqlall.pid --socket=/tmp/mysqls810.sock --port=13381
[root@lhrmysqlall data801913380]# netstat -tulnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 192/sshd
tcp 0 0 127.0.0.1:3350 0.0.0.0:* LISTEN 189/xrdp-sesman
tcp 0 0 0.0.0.0:3389 0.0.0.0:* LISTEN 190/xrdp
tcp 0 0 0.0.0.0:13321 0.0.0.0:* LISTEN 1080/mysqld
tcp6 0 0 :::13331 :::* LISTEN 1143/mysqld
tcp6 0 0 :::22 :::* LISTEN 192/sshd
tcp6 0 0 :::13341 :::* LISTEN 1221/mysqld
tcp6 0 0 :::13380 :::* LISTEN 1269/mysqld
tcp6 0 0 :::33060 :::* LISTEN 1276/mysqld
tcp6 0 0 :::13381 :::* LISTEN 1276/mysqld
[root@lhrmysqlall data801913380]#
[root@lhrmysqlall ~]# dbdeployer sandboxes
group_msb_8_0_19 : group-multi-primary 8.0.19 [13371 13496 23371 13372 13497 23372 13373 13498 23373 ]
msb_5_5_62 : single 5.5.62 [13351 ]
msb_5_6_48 : single 5.6.48 [13352 ]
msb_5_7_30 : single 5.7.30 [13353 ]
msb_8_0_19 : single 8.0.19 [13354 23354 ]
rsandbox_5_7_30 : master-slave 5.7.30 [13361 13362 ]
[root@lhrmysqlall ~]#