在docker环境中,快速体验各个版本的MySQL数据库(从5.5到8.4)

教育   2024-12-02 19:42   陕西  

官方镜像

https://hub.docker.com/_/mysql

http://hub.daocloud.io

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.37 &
10nohup docker pull mysql:8.4.0 &
11
12
13docker rm mysql55 -f
14docker rm mysql56 -f
15docker rm mysql57 -f
16docker rm mysql80 -f
17docker rm mysql84 -f
18
19
20mkdir -p /etc/mysql/mysql55/conf
21mkdir -p /etc/mysql/mysql56/conf
22mkdir -p /etc/mysql/mysql57/conf
23mkdir -p /etc/mysql/mysql80/conf
24mkdir -p /etc/mysql/mysql84/conf
25
26
27cat >  /etc/mysql/mysql55/conf/my.cnf <<"EOF"
28[mysqld]
29skip-name-resolve
30log-bin
31server_id=553415
32character_set_server=utf8mb4
33EOF
34
35cat >  /etc/mysql/mysql56/conf/my.cnf <<"EOF"
36[mysqld]
37skip-name-resolve
38log-bin
39server_id=563416
40character_set_server=utf8mb4
41EOF
42
43cat >  /etc/mysql/mysql57/conf/my.cnf <<"EOF"
44[mysqld]
45default-time-zone = '+8:00'
46log_timestamps = SYSTEM
47skip-name-resolve
48log-bin
49server_id=573417
50character_set_server=utf8mb4
51EOF
52
53cat >  /etc/mysql/mysql80/conf/my.cnf <<"EOF"
54[mysqld]
55default-time-zone = '+8:00'
56log_timestamps = SYSTEM
57skip-name-resolve
58log-bin
59server_id=803418
60character_set_server=utf8mb4
61default_authentication_plugin=mysql_native_password
62EOF
63
64
65cat >  /etc/mysql/mysql84/conf/my.cnf <<"EOF"
66[mysqld]
67default-time-zone = '+8:00'
68log_timestamps = SYSTEM
69skip-name-resolve
70log-bin
71server_id=843419
72character_set_server=utf8mb4
73mysql_native_password=on
74EOF
75
76
77
78docker run -d --name mysql55 -h mysql55 -p 3415:3306 \
79  -v /etc/mysql/mysql55/conf:/etc/mysql/conf.d \
80  -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \
81  mysql:5.5.62
82
83docker run -d --name mysql56 -h mysql56 -p 3416:3306 \
84  -v /etc/mysql/mysql56/conf:/etc/mysql/conf.d \
85  -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \
86  mysql:5.6.51
87
88docker run -d --name mysql57 -h mysql57 -p 3417:3306 \
89  -v /etc/mysql/mysql57/conf:/etc/mysql/conf.d \
90  -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \
91  mysql:5.7.44
92
93docker run -d --name mysql80 -h mysql80 -p 3418:3306 \
94  -v /etc/mysql/mysql80/conf:/etc/mysql/conf.d \
95  -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \
96  mysql:8.0.37
97
98docker run -d --name mysql84 -h mysql84 -p 3419:3306 \
99  -v /etc/mysql/mysql84/conf:/etc/mysql/conf.d \
100  -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \
101  mysql:8.4.0
102
103
104docker logs -f mysql55
105docker logs -f mysql56
106docker logs -f mysql57
107docker logs -f mysql80
108docker logs -f mysql84
109
110
111
112mysql -uroot -plhr -h127.0.0.1 -P3415 -e "select now(),@@hostname,@@version;"
113mysql -uroot -plhr -h127.0.0.1 -P3416 -e "select now(),@@hostname,@@version;"
114mysql -uroot -plhr -h127.0.0.1 -P3417 -e "select now(),@@hostname,@@version;"
115mysql -uroot -plhr -h127.0.0.1 -P3418 -e "select now(),@@hostname,@@version;"
116mysql -uroot -plhr -h127.0.0.1 -P3419 -e "select now(),@@hostname,@@version;"
117
118
119docker restart mysql55 mysql56 mysql57 mysql80  mysql84

检查版本

 1[root@lhrdb ~]# mysql -uroot -plhr -h127.0.0.1 -P3415 -e "select now(),@@hostname,@@version;"
2+---------------------+------------+------------+
3| now()               | @@hostname | @@version  |
4+---------------------+------------+------------+
5| 2023-08-21 12:35:29 | mysql55    | 5.5.62-log |
6+---------------------+------------+------------+
7[root@lhrdb ~]# mysql -uroot -plhr -h127.0.0.1 -P3416 -e "select now(),@@hostname,@@version;"
8+---------------------+------------+------------+
9| now()               | @@hostname | @@version  |
10+---------------------+------------+------------+
11| 2023-08-21 12:35:29 | 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-05-09 09:14:24 | 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-05-09 09:14:26 | mysql80    | 8.0.37    |
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-05-09 09:09:46 | mysql84    | 8.4.0     |
30+---------------------+------------+-----------+

示例

 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 ~]#

AiDBA
【PostgreSQL培训认证】【Oracle OCP、OCM、高可用(RAC+DG+OGG)培训认证】【MySQL OCP培训认证】【GreenPlum培训】【SQL Server培训】官网:www.dbaup.com,学习不止数据库
 最新文章