原 在Docker中快速使用各个版本的MySQL数据库
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 | # 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 |
检查版本
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 | [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 | +---------------------+------------+-----------+ |