下载下面三个版本的通用安装包:
https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz
解压到/usr/local目录并创建软连接:
# cd /usr/local # tar xvf ~/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz # tar xvf ~/mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz # tar xvf ~/mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz # ln -s mysql-5.7.35-linux-glibc2.12-x86_64 mysql57 # ln -s mysql-5.6.51-linux-glibc2.12-x86_64 mysql56 # ln -s mysql-8.0.27-linux-glibc2.12-x86_64 mysql80
初始化数据:
# yum install -y perl # yum install -y autoconf # yum install -y libaio # mkdir -p /usr/local/mysql80/data # mysql80/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql80/data # mysql57/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql57/data # cd mysql56 # scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql56/data
5.6初始化需要进入到mysql56目录下进行。
在数据初始化的过程中8.0和5.7会初始生成一个临时密码,5.6生成的是空密码,登录后修改密码。在5.6中修改密码的命令有所不同:
mysql> set password=password('yaoyuan');
编辑一个mysql的配置文件,/etc/my.cnf
[client] user=root password=yaoyuan [mysql] prompt=(\\u@\\h) [\\d]>\\_ [mysqld_multi] mysqld = /usr/local/mysql80/bin/mysqld_safe #启动时调用的命令 mysqladmin = /usr/local/mysql80/bin/mysqladmin #关闭时调用的命令 下面需要提供用户和密码 [mysqld56] mysqladmin = /usr/local/mysql56/bin/mysqladmin # 需要用5.6自己的关机命令 basedir=/usr/local/mysql56 socket = /tmp/mysql.sock56 port = 3307 datadir = /usr/local/mysql56/data [mysqld57] basedir=/usr/local/mysql57 socket = /tmp/mysql.sock57 port = 3308 datadir = /usr/local/mysql57/data [mysqld80] basedir=/usr/local/mysql80 socket = /tmp/mysql.sock80 port = 3309 datadir = /usr/local/mysql80/data
[mysqld_multi]下面要指定关闭用的用户名和密码,这个用户需要有shutdown的权限。也可以配置到[mysql]下面,如果配置到[mysqld_multi]下面需要把password改成pass,不然无法关机,这里官方文档错了。
MySQL 8.0的关机命令对MySQL 5.6步适用,会出错:
# /usr/local/mysql/bin/mysqladmin shutdown -S /tmp/mysql.sock56 mysqladmin: shutdown failed; error: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'shutdown' at line 1'
启动或关闭MySQL不同版本的进程,并检查状态:
[root@mysql_g bin]# mysqld_multi start 56,57,80 [root@mysql_g bin]# mysqld_multi report Reporting MySQL servers MySQL server from group: mysqld56 is running MySQL server from group: mysqld57 is running MySQL server from group: mysqld80 is running [root@mysql_g ~]# ps -ef|grep mysqld root 3181 1 0 02:49 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --basedir=/usr/local/mysql57 --socket=/tmp/mysql.sock57 --port=3308 --datadir=/usr/local/mysql57/data mysql 3300 3181 0 02:49 pts/1 00:00:01 /usr/local/mysql57/bin/mysqld --basedir=/usr/local/mysql57 --datadir=/usr/local/mysql57/data --plugin-dir=/usr/local/mysql57/lib/plugin --user=mysql --log-error=mysql_g.localdomain.err --pid-file=mysql_g.localdomain.pid --socket=/tmp/mysql.sock57 --port=3308 root 3665 1 0 03:02 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --basedir=/usr/local/mysql56 --socket=/tmp/mysql.sock56 --port=3307 --datadir=/usr/local/mysql56/data mysql 3794 3665 0 03:02 pts/1 00:00:01 /usr/local/mysql56/bin/mysqld --basedir=/usr/local/mysql56 --datadir=/usr/local/mysql56/data --plugin-dir=/usr/local/mysql56/lib/plugin --user=mysql --log-error=mysql_g.localdomain.err --pid-file=mysql_g.localdomain.pid --socket=/tmp/mysql.sock56 --port=3307 root 3851 1 0 03:11 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --basedir=/usr/local/mysql80 --socket=/tmp/mysql.sock80 --port=3309 --datadir=/usr/local/mysql80/data mysql 3970 3851 11 03:11 pts/1 00:00:01 /usr/local/mysql80/bin/mysqld --basedir=/usr/local/mysql80 --datadir=/usr/local/mysql80/data --plugin-dir=/usr/local/mysql80/lib/plugin --user=mysql --log-error=mysql_g.localdomain.err --pid-file=mysql_g.localdomain.pid --socket=/tmp/mysql.sock80 --port=3309 root 4028 2966 0 03:11 pts/1 00:00:00 grep --color=auto mysqld [root@mysql_g ~]# mysqld_multi stop 57 [root@mysql_g ~]# mysqld_multi report Reporting MySQL servers MySQL server from group: mysqld56 is running MySQL server from group: mysqld57 is not running MySQL server from group: mysqld80 is running
连接进入MySQL 5.6,注意sock端口:
[root@mysql_g bin]# mysql -S /tmp/mysql.sock56 -uroot -pyaoyuan 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 4 Server version: 5.6.51 MySQL Community Server (GPL) Copyright (c) 2000, 2021, 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. (root@localhost) [(none)]> select @@version; +-----------+ | @@version | +-----------+ | 5.6.51 | +-----------+ 1 row in set (0.00 sec)