⛳️ 1.安装包下载
官网链接
https://dev.mysql.com/downloads/mysql/
此次我们部署4个版本
⛳️ 2.安装部署
🐴 2.1 环境部署
[root@centos7 ~]# mkdir /soft --上传软件包
#初始化一个容器作为主机
docker run -d --name mysqlhost02 -h mysqlhost02
-p 232:22 -p 3506-3606:3506-3606
-v /sys/fs/cgroup:/sys/fs/cgroup
–privileged=true
–network=mynet --ip 172.18.12.9
centos:7.6.1810 /usr/sbin/init
[root@centos7 ~]# docker ps --查询容器
[root@centos7 ~]# docker update --restart=always mysqlhost02 --开机自启动
[root@centos7 ~]# docker exec -it mysqlhost02 bash
🐴 2.2 安装包拷到容器
#把安装包拷贝到容器里边
[root@mysqlhost02 /]# mkdir /soft
[root@centos7 soft]# docker cp mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz mysqlhost02:/soft/
[root@centos7 soft]# docker cp mysql-5.6.48-linux-glibc2.12-x86_64.tar.gz mysqlhost02:/soft/
[root@centos7 soft]# docker cp mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz mysqlhost02:/soft/
[root@centos7 soft]# docker cp mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz mysqlhost02:/soft/
🐴 2.3 二进制方式安装 MySQL
[root@mysqlhost02 ~]# mkdir -p /usr/local/mysqlsoft [root@mysqlhost02 soft]# tar -zxvf mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz -C /usr/local/mysqlsoft [root@mysqlhost02 soft]# tar -zxvf mysql-5.6.48-linux-glibc2.12-x86_64.tar.gz -C /usr/local/mysqlsoft [root@mysqlhost02 soft]# tar -zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/mysqlsoft [root@mysqlhost02 soft]# tar -Jxf mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz -C /usr/local/mysqlsoft [root@mysqlhost02 soft]# cd /usr/local/mysqlsoft [root@mysqlhost02 mysqlsoft]# du -sh ./* 752M ./mysql-5.5.62-linux-glibc2.12-x86_64 1.2G ./mysql-5.6.48-linux-glibc2.12-x86_64 2.5G ./mysql-5.7.30-linux-glibc2.12-x86_64 2.5G ./mysql-8.0.19-linux-glibc2.12-x86_64 #快捷方式创建 [root@mysqlhost02 /]# mkdir -p /usr/local/mysql55 [root@mysqlhost02 /]# mkdir -p /usr/local/mysql56 [root@mysqlhost02 /]# mkdir -p /usr/local/mysql57 [root@mysqlhost02 /]# mkdir -p /usr/local/mysql80 ln -s /usr/local/mysqlsoft/mysql-5.5.62-linux-glibc2.12-x86_64 /usr/local/mysql55/mysql5562 ln -s /usr/local/mysqlsoft/mysql-5.6.48-linux-glibc2.12-x86_64 /usr/local/mysql56/mysql5648 ln -s /usr/local/mysqlsoft/mysql-5.7.30-linux-glibc2.12-x86_64 /usr/local/mysql57/mysql5730 ln -s /usr/local/mysqlsoft/mysql-8.0.19-linux-glibc2.12-x86_64 /usr/local/mysql80/mysql8019
[root@mysqlhost02 local]# ll
[root@mysqlhost02 mysql55]# ll lrwxrwxrwx 1 root root 56 Feb 28 15:15 mysql5562 -> /usr/local/mysqlsoft/mysql-5.5.62-linux-glibc2.12-x86_64 [root@mysqlhost02 ~]# groupadd mysql [root@mysqlhost02 ~]# useradd -r -g mysql mysql [root@mysqlhost02 ~]# chown -R mysql.mysql /usr/local/mysqlsoft/ [root@mysqlhost02 ~]# cd /usr/local/mysqlsoft/ [root@mysqlhost02 mysqlsoft]# ll drwxr-xr-x 13 mysql mysql 256 Feb 28 15:15 mysql-5.5.62-linux-glibc2.12-x86_64 drwxr-xr-x 13 mysql mysql 234 Feb 28 15:15 mysql-5.6.48-linux-glibc2.12-x86_64 drwxr-xr-x 9 mysql mysql 172 Feb 28 15:15 mysql-5.7.30-linux-glibc2.12-x86_64 drwxr-xr-x 9 mysql mysql 172 Feb 28 15:16 mysql-8.0.19-linux-glibc2.12-x86_64 --必须yum安装这个 yum install libaio --- 5.5、5.6 --MySQL 5.5、5.6 的二进制安装默认密码为空 /usr/local/mysql55/mysql5562/scripts/mysql_install_db --user=mysql \ --basedir=/usr/local/mysql55/mysql5562 --datadir=/usr/local/mysql55/mysql5562/data -必须yum安装这个 yum -y install perl perl-devel yum -y install autoconf yum remove libnuma.so.1 yum -y install numactl.x86_64 /usr/local/mysql56/mysql5648/scripts/mysql_install_db --user=mysql \ --basedir=/usr/local/mysql56/mysql5648 --datadir=/usr/local/mysql56/mysql5648/data -- MySQL 5.7.6 之后的版本初始化数据库不再使用 mysql_install_db(insecure为空密码) /usr/local/mysql57/mysql5730/bin/mysqld --initialize-insecure --user=mysql \ --basedir=/usr/local/mysql57/mysql5730 --datadir=/usr/local/mysql57/mysql5730/data /usr/local/mysql80/mysql8019/bin/mysqld --initialize-insecure --user=mysql \ --basedir=/usr/local/mysql80/mysql8019 --datadir=/usr/local/mysql80/mysql8019/data
🐴 2.4 环境变量创建
#环境变量创建
[root@mysqlhost02 ~]# echo “export PATH=$PATH:/usr/local/mysql80/mysql8019/bin” >> /root/.bashrc
[root@mysqlhost02 ~]# source /root/.bashrc
[root@mysqlhost02 ~]# mysqld_multi report
⛳️ 3.管理多实例
#/etc/my.cnf 管理多实例 [root@mysqlhost02 ~]# mkdir -p /usr/local/mysqlsoft/log/ [root@mysqlhost02 ~]# vi /etc/my.cnf [mysqld_multi] mysqld=/usr/local/mysql80/mysql8019/bin/mysqld_safe mysqladmin=/usr/local/mysql80/mysql8019/bin/mysqladmin log=/usr/local/mysqlsoft/log/mysqld_multi.log user=root password=root [mysql] default-character-set=utf8mb4 [mysqld55623506] mysqld=/usr/local/mysql55/mysql5562/bin/mysqld_safe mysqladmin=/usr/local/mysql55/mysql5562/bin/mysqladmin port=3506 basedir=/usr/local/mysql55/mysql5562 datadir=/usr/local/mysql55/mysql5562/data socket=/usr/local/mysql55/mysql5562/data/mysqls55623506.sock server_id=55623506 log-bin skip-name-resolve character_set_server=utf8mb4 [mysqld56483507] mysqld=/usr/local/mysql56/mysql5648/bin/mysqld_safe mysqladmin=/usr/local/mysql56/mysql5648/bin/mysqladmin port=3507 basedir=/usr/local/mysql56/mysql5648 datadir=/usr/local/mysql56/mysql5648/data socket=/usr/local/mysql56/mysql5648/data/mysqls56483507.sock server_id=56483507 log-bin skip-name-resolve character_set_server=utf8mb4 [mysqld57303508] mysqld=/usr/local/mysql57/mysql5730/bin/mysqld_safe mysqladmin=/usr/local/mysql57/mysql5730/bin/mysqladmin port=3508 basedir=/usr/local/mysql57/mysql5730 datadir=/usr/local/mysql57/mysql5730/data socket=/usr/local/mysql57/mysql5730/data/mysqls57303508.sock server_id=57303508 log-bin default-time-zone = '+8:00' log_timestamps = SYSTEM skip-name-resolve character_set_server=utf8mb4 [mysqld80193509] mysqld=/usr/local/mysql80/mysql8019/bin/mysqld_safe mysqladmin=/usr/local/mysql80/mysql8019/bin/mysqladmin port=3509 basedir=/usr/local/mysql80/mysql8019 datadir=/usr/local/mysql80/mysql8019/data socket=/usr/local/mysql80/mysql8019/data/mysqls80193509.sock default_authentication_plugin=mysql_native_password server_id=80193509 log-bin default-time-zone = '+8:00' log_timestamps = SYSTEM skip-name-resolve character_set_server=utf8mb4
⛳️ 4.Mysql启动
[root@mysqlhost02 ~]# mysqld_multi report
[root@mysqlhost02 ~]# mysqld_multi start 55623506 [root@mysqlhost02 ~]# mysqld_multi report Reporting MySQL servers MySQL server from group: mysqld55623506 is running MySQL server from group: mysqld56483507 is not running MySQL server from group: mysqld57303508 is not running MySQL server from group: mysqld80193509 is not running 通过socket登陆 [root@mysqlhost02 ~]# ps -ef | grep mysql55 [root@mysqlhost02 ~]# mysql -uroot -p -S /usr/local/mysql55/mysql5562/data/mysqls55623506.sock [root@mysqlhost02 ~]# ALTER USER 'root'@'localhost' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY 'root'; --mysql8 注意:要设置密码,负责无法关闭 [root@mysqlhost02 ~]# mysqld_multi start 56483507,57303508 [root@mysqlhost02 ~]# mysqld_multi report Reporting MySQL servers MySQL server from group: mysqld55623506 is running MySQL server from group: mysqld56483507 is running MySQL server from group: mysqld57303508 is running MySQL server from group: mysqld80193509 is not running