原 在Docker中快速使用各个版本的MySQL数据库(从5.5到9.1)
Tags: 原创MySQLDocker快速体验各个版本MySQL 8.4
官方镜像
https://hub.docker.com/_/mysql
5.1、5.5、5.6、5.7+ 、 8.0+ 、 8.4+ 都是LTS(Long Term Support,长期支持版本)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | # 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.40 & nohup docker pull mysql:8.4.3 & nohup docker pull mysql:9.1.0 & docker rm mysql55 -f docker rm mysql56 -f docker rm mysql57 -f docker rm mysql80 -f docker rm mysql84 -f docker rm mysql91 -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 mkdir -p /etc/mysql/mysql91/conf cat > /etc/mysql/mysql55/conf/my.cnf <<"EOF" [mysqld] skip-name-resolve log-bin server_id=553306 character_set_server=utf8mb4 EOF cat > /etc/mysql/mysql56/conf/my.cnf <<"EOF" [mysqld] skip-name-resolve log-bin server_id=563306 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=573306 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=843306 character_set_server=utf8mb4 mysql_native_password=on EOF cat > /etc/mysql/mysql91/conf/my.cnf <<"EOF" [mysqld] default-time-zone = '+8:00' log_timestamps = SYSTEM skip-name-resolve log-bin server_id=913306 character_set_server=utf8mb4 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.40 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.3 docker run -d --name mysql91 -h mysql91 -p 3420:3306 \ -v /etc/mysql/mysql91/conf:/etc/mysql/conf.d \ -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \ mysql:9.1.0 docker logs -f mysql55 docker logs -f mysql56 docker logs -f mysql57 docker logs -f mysql80 docker logs -f mysql84 docker logs -f mysql91 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;" mysql -uroot -plhr -h127.0.0.1 -P3420 -e "select now(),@@hostname,@@version;" docker restart mysql55 mysql56 mysql57 mysql80 mysql84 |
检查版本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | [root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3415 -e "select now(),@@hostname,@@version;" +---------------------+------------+------------+ | now() | @@hostname | @@version | +---------------------+------------+------------+ | 2024-12-03 10:34:22 | mysql55 | 5.5.62-log | +---------------------+------------+------------+ [root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3416 -e "select now(),@@hostname,@@version;" +---------------------+------------+------------+ | now() | @@hostname | @@version | +---------------------+------------+------------+ | 2024-12-03 10:34:22 | mysql56 | 5.6.51-log | +---------------------+------------+------------+ [root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3417 -e "select now(),@@hostname,@@version;" +---------------------+------------+------------+ | now() | @@hostname | @@version | +---------------------+------------+------------+ | 2024-12-03 10:34:22 | mysql57 | 5.7.44-log | +---------------------+------------+------------+ [root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3418 -e "select now(),@@hostname,@@version;" +---------------------+------------+-----------+ | now() | @@hostname | @@version | +---------------------+------------+-----------+ | 2024-12-03 10:34:22 | mysql80 | 8.0.40 | +---------------------+------------+-----------+ [root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3419 -e "select now(),@@hostname,@@version;" +---------------------+------------+-----------+ | now() | @@hostname | @@version | +---------------------+------------+-----------+ | 2024-12-03 10:34:22 | mysql84 | 8.4.3 | +---------------------+------------+-----------+ [root@alldb ~]# mysql -uroot -plhr -h127.0.0.1 -P3420 -e "select now(),@@hostname,@@version;" +---------------------+------------+-----------+ | now() | @@hostname | @@version | +---------------------+------------+-----------+ | 2024-12-03 10:34:22 | mysql91 | 9.1.0 | +---------------------+------------+-----------+ |
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | 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) |