官方镜像
https://hub.docker.com/_/mysql
5.1、5.5、5.6、5.7+ 、 8.0+ 、 8.4+ 都是LTS(Long Term Support,长期支持版本)
1# registry.cn-hangzhou.aliyuncs.com/lhrbest/
2
3docker search mysql
4
5
6nohup docker pull mysql:5.5.62 &
7nohup docker pull mysql:5.6.51 &
8nohup docker pull mysql:5.7.44 &
9nohup docker pull mysql:8.0.40 &
10nohup docker pull mysql:8.4.3 &
11nohup docker pull mysql:9.1.0 &
12
13
14docker rm mysql55 -f
15docker rm mysql56 -f
16docker rm mysql57 -f
17docker rm mysql80 -f
18docker rm mysql84 -f
19docker rm mysql91 -f
20
21
22mkdir -p /etc/mysql/mysql55/conf
23mkdir -p /etc/mysql/mysql56/conf
24mkdir -p /etc/mysql/mysql57/conf
25mkdir -p /etc/mysql/mysql80/conf
26mkdir -p /etc/mysql/mysql84/conf
27mkdir -p /etc/mysql/mysql91/conf
28
29
30cat > /etc/mysql/mysql55/conf/my.cnf <<"EOF"
31[mysqld]
32skip-name-resolve
33log-bin
34server_id=553306
35character_set_server=utf8mb4
36EOF
37
38cat > /etc/mysql/mysql56/conf/my.cnf <<"EOF"
39[mysqld]
40skip-name-resolve
41log-bin
42server_id=563306
43character_set_server=utf8mb4
44EOF
45
46cat > /etc/mysql/mysql57/conf/my.cnf <<"EOF"
47[mysqld]
48default-time-zone = '+8:00'
49log_timestamps = SYSTEM
50skip-name-resolve
51log-bin
52server_id=573306
53character_set_server=utf8mb4
54EOF
55
56cat > /etc/mysql/mysql80/conf/my.cnf <<"EOF"
57[mysqld]
58default-time-zone = '+8:00'
59log_timestamps = SYSTEM
60skip-name-resolve
61log-bin
62server_id=803418
63character_set_server=utf8mb4
64default_authentication_plugin=mysql_native_password
65EOF
66
67
68cat > /etc/mysql/mysql84/conf/my.cnf <<"EOF"
69[mysqld]
70default-time-zone = '+8:00'
71log_timestamps = SYSTEM
72skip-name-resolve
73log-bin
74server_id=843306
75character_set_server=utf8mb4
76mysql_native_password=on
77EOF
78
79
80cat > /etc/mysql/mysql91/conf/my.cnf <<"EOF"
81[mysqld]
82default-time-zone = '+8:00'
83log_timestamps = SYSTEM
84skip-name-resolve
85log-bin
86server_id=913306
87character_set_server=utf8mb4
88EOF
89
90
91
92docker run -d --name mysql55 -h mysql55 -p 3415:3306 \
93 -v /etc/mysql/mysql55/conf:/etc/mysql/conf.d \
94 -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \
95 mysql:5.5.62
96
97docker run -d --name mysql56 -h mysql56 -p 3416:3306 \
98 -v /etc/mysql/mysql56/conf:/etc/mysql/conf.d \
99 -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \
100 mysql:5.6.51
101
102docker run -d --name mysql57 -h mysql57 -p 3417:3306 \
103 -v /etc/mysql/mysql57/conf:/etc/mysql/conf.d \
104 -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \
105 mysql:5.7.44
106
107docker run -d --name mysql80 -h mysql80 -p 3418:3306 \
108 -v /etc/mysql/mysql80/conf:/etc/mysql/conf.d \
109 -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \
110 mysql:8.0.40
111
112docker run -d --name mysql84 -h mysql84 -p 3419:3306 \
113 -v /etc/mysql/mysql84/conf:/etc/mysql/conf.d \
114 -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \
115 mysql:8.4.3
116
117
118docker run -d --name mysql91 -h mysql91 -p 3420:3306 \
119 -v /etc/mysql/mysql91/conf:/etc/mysql/conf.d \
120 -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \
121 mysql:9.1.0
122
123
124docker logs -f mysql55
125docker logs -f mysql56
126docker logs -f mysql57
127docker logs -f mysql80
128docker logs -f mysql84
129docker logs -f mysql91
130
131
132
133mysql -uroot -plhr -h127.0.0.1 -P3415 -e "select now(),@@hostname,@@version;"
134mysql -uroot -plhr -h127.0.0.1 -P3416 -e "select now(),@@hostname,@@version;"
135mysql -uroot -plhr -h127.0.0.1 -P3417 -e "select now(),@@hostname,@@version;"
136mysql -uroot -plhr -h127.0.0.1 -P3418 -e "select now(),@@hostname,@@version;"
137mysql -uroot -plhr -h127.0.0.1 -P3419 -e "select now(),@@hostname,@@version;"
138mysql -uroot -plhr -h127.0.0.1 -P3420 -e "select now(),@@hostname,@@version;"
139
140
141docker restart mysql55 mysql56 mysql57 mysql80 mysql84
检查版本
1[root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3415 -e "select now(),@@hostname,@@version;"
2+---------------------+------------+------------+
3| now() | @@hostname | @@version |
4+---------------------+------------+------------+
5| 2024-12-03 10:34:22 | mysql55 | 5.5.62-log |
6+---------------------+------------+------------+
7[root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3416 -e "select now(),@@hostname,@@version;"
8+---------------------+------------+------------+
9| now() | @@hostname | @@version |
10+---------------------+------------+------------+
11| 2024-12-03 10:34:22 | mysql56 | 5.6.51-log |
12+---------------------+------------+------------+
13[root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3417 -e "select now(),@@hostname,@@version;"
14+---------------------+------------+------------+
15| now() | @@hostname | @@version |
16+---------------------+------------+------------+
17| 2024-12-03 10:34:22 | mysql57 | 5.7.44-log |
18+---------------------+------------+------------+
19[root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3418 -e "select now(),@@hostname,@@version;"
20+---------------------+------------+-----------+
21| now() | @@hostname | @@version |
22+---------------------+------------+-----------+
23| 2024-12-03 10:34:22 | mysql80 | 8.0.40 |
24+---------------------+------------+-----------+
25[root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3419 -e "select now(),@@hostname,@@version;"
26+---------------------+------------+-----------+
27| now() | @@hostname | @@version |
28+---------------------+------------+-----------+
29| 2024-12-03 10:34:22 | mysql84 | 8.4.3 |
30+---------------------+------------+-----------+
31[root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3420 -e "select now(),@@hostname,@@version;"
32+---------------------+------------+-----------+
33| now() | @@hostname | @@version |
34+---------------------+------------+-----------+
35| 2024-12-03 10:34:22 | mysql91 | 9.1.0 |
36+---------------------+------------+-----------+
示例
1root@lhrxxt:~# docker run -d --name mysql8030 -h mysql8030 -p 3418:3306 \
2> -v /etc/mysql/mysql8030/conf:/etc/mysql/conf.d \
3> -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \
4> mysql:8.0.30
5f6e94a91fd69e26d0e9e7bd5b4ef11ecde0f4b8502299c537342141ea01bf80a
6root@lhrxxt:~#
7root@lhrxxt:~# cat > /etc/mysql/mysql8030/conf/my.cnf <<"EOF"
8> [mysqld]
9> default-time-zone = '+8:00'
10> log_timestamps = SYSTEM
11> skip-name-resolve
12> log-bin
13> server_id=80303418
14> character_set_server=utf8mb4
15> EOF
16root@lhrxxt:~# docker restart mysql8030
17mysql8030
18root@lhrxxt:~# docker exec -it mysql8030 bash
19bash-4.4# mysql
20ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
21bash-4.4# mysql -uroot -plhr
22mysql: [Warning] Using a password on the command line interface can be insecure.
23Welcome to the MySQL monitor. Commands end with ; or \g.
24Your MySQL connection id is 9
25Server version: 8.0.30 MySQL Community Server - GPL
26
27Copyright (c) 2000, 2022, Oracle and/or its affiliates.
28
29Oracle is a registered trademark of Oracle Corporation and/or its
30affiliates. Other names may be trademarks of their respective
31owners.
32
33Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
34
35mysql> show databases;
36+--------------------+
37| Database |
38+--------------------+
39| information_schema |
40| mysql |
41| performance_schema |
42| sys |
43+--------------------+
444 rows in set (0.05 sec)
45
46mysql> create database lhrdb;
47Query OK, 1 row affected (0.04 sec)
48
49mysql> show databases;
50+--------------------+
51| Database |
52+--------------------+
53| information_schema |
54| lhrdb |
55| mysql |
56| performance_schema |
57| sys |
58+--------------------+
595 rows in set (0.00 sec)
麦老师镜像
1docker rm -f lhrmysqlall
2docker run -d --name lhrmysqlall -h lhrmysqlall \
3-p 13306-13406:13306-13406 -p 222:22 \
4-v /sys/fs/cgroup:/sys/fs/cgroup \
5--privileged=true \
6lhrbest/lhrmysqlall:2.0 /usr/sbin/init
7
8docker exec -it lhrmysqlall bash
9
10
11mysqld_multi report
示例:
1[root@lhrmysqlall /]# mysqld_multi report
2Reporting MySQL servers
3MySQL server from group: mysqld556213321 is not running
4MySQL server from group: mysqld564813331 is not running
5MySQL server from group: mysqld573013341 is not running
6MySQL server from group: mysqld801913380 is not running
7MySQL server from group: mysqld810 is not running
8[root@lhrmysqlall /]# mysqld_multi start
9[root@lhrmysqlall /]# mysqld_multi report
10Reporting MySQL servers
11MySQL server from group: mysqld556213321 is running
12MySQL server from group: mysqld564813331 is running
13MySQL server from group: mysqld573013341 is running
14MySQL server from group: mysqld801913380 is running
15MySQL server from group: mysqld810 is running
16[root@lhrmysqlall /]# ps -ef|grep mysql
17root 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
18root 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
19root 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
20root 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
21root 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
22mysql 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
23mysql 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
24mysql 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
25mysql 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
26mysql 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
27root 1495 64 0 16:09 pts/0 00:00:00 grep --color=auto mysql
28[root@lhrmysqlall /]# ps -ef|grep mysqld
29root 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
30root 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
31root 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
32root 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
33root 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
34mysql 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
35mysql 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
36mysql 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
37mysql 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
38mysql 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
39
40[root@lhrmysqlall data801913380]# netstat -tulnp
41Active Internet connections (only servers)
42Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
43tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 192/sshd
44tcp 0 0 127.0.0.1:3350 0.0.0.0:* LISTEN 189/xrdp-sesman
45tcp 0 0 0.0.0.0:3389 0.0.0.0:* LISTEN 190/xrdp
46tcp 0 0 0.0.0.0:13321 0.0.0.0:* LISTEN 1080/mysqld
47tcp6 0 0 :::13331 :::* LISTEN 1143/mysqld
48tcp6 0 0 :::22 :::* LISTEN 192/sshd
49tcp6 0 0 :::13341 :::* LISTEN 1221/mysqld
50tcp6 0 0 :::13380 :::* LISTEN 1269/mysqld
51tcp6 0 0 :::33060 :::* LISTEN 1276/mysqld
52tcp6 0 0 :::13381 :::* LISTEN 1276/mysqld
53[root@lhrmysqlall data801913380]#
54[root@lhrmysqlall ~]# dbdeployer sandboxes
55 group_msb_8_0_19 : group-multi-primary 8.0.19 [13371 13496 23371 13372 13497 23372 13373 13498 23373 ]
56 msb_5_5_62 : single 5.5.62 [13351 ]
57 msb_5_6_48 : single 5.6.48 [13352 ]
58 msb_5_7_30 : single 5.7.30 [13353 ]
59 msb_8_0_19 : single 8.0.19 [13354 23354 ]
60 rsandbox_5_7_30 : master-slave 5.7.30 [13361 13362 ]
61[root@lhrmysqlall ~]#
参考
https://en.wikipedia.org/wiki/MySQL