<返回更多

MySQL不同版本多实例部署

2021-07-05  今日头条  智明杂谈
加入收藏

1 背景介绍

我们在数据库运维的过程中.会遇到不同版本的数据库部署需求.同时测试环境数据库需求更是不同.有时为了节省资源.我们需要进行多实例的部署.或者在我们自己学习的过程中也需要进行多实例的部署..比如搭建各种MySQL的集群(mha,PXC,Xenon).这篇文章我将介绍多版本多实例的部署.

2 部署介绍

多版本多实例版本介绍:

下载对应版本MySQL

2.1 软件下载

下载地址:https://downloads.mysql.com/archives/community/

 

MySQL不同版本多实例部署

下载对应版本MySQL二进制安装包

2.2 解压对应软件,并做软链接

root@dba1 opt]# ll
-rw-r--r-- 1 root  root  304788904 Jul  3 21:50 mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
-rw-r--r-- 1 root  root  661718255 Jul  3 21:52 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
-rw-r--r--  1 root root  347814208 Jul  4 02:17 mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz

解压:
tar xf mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz 
tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
tar xf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz 

软链接:
[root@db01 opt]# ln -s /opt/mysql-5.6.16-linux-glibc2.5-x86_64 /usr/local/mysql5616
[root@db01 opt]# ln -s /opt/mysql-5.7.33-linux-glibc2.12-x86_64 /usr/local/mysql5733
[root@db01 opt]# ln -s /opt/mysql-8.0.21-linux-glibc2.12-x86_64 /usr/local/mysql8021

2.3 创建对应的数据目录

mkdir /data/5616/data -p
mkdir /data/5733/data -p
mkdir /data/8021/data -p
[root@db01 opt]# ll /data/
total 0
drwxr-xr-x 3 root root 18 Jul  4 02:21 5616
drwxr-xr-x 3 root root 18 Jul  4 02:21 5733
drwxr-xr-x 3 root root 18 Jul  4 02:22 8021

2.4 对应版本的配置文件准备


[root@db01 var]# cat /data/5616/my.cnf 
[mysqld] ?
user=mysql
basedir=/usr/local/mysql5616
datadir=/data/5616/data
socket=/tmp/mysql5616.sock
server_id=56
port=3306


[root@db01 var]# cat /data/5733/my.cnf 
[mysqld]
user=mysql
basedir=/usr/local/mysql5733
datadir=/data/5733/data
socket=/tmp/mysql5733.sock
server_id=57
port=3307


[root@db01 var]# cat /data/8021/my.cnf 
[mysqld]
user=mysql
basedir=/usr/local/mysql8021
datadir=/data/8021/data
socket=/tmp/mysql8021.sock
server_id=80
port=3308


授权MySQL
[root@db01 opt]# chown -R mysql.mysql /data

3 初始化对应版本的数据库

在这里需要注意的是MySQL5.6版本的初始化方式和5.7 8.0初始化方式不同
MySQL5.6初始化是调用程序目录下边的mysql_install_db脚本进行初始化
首先初始化5.6版本数据库
[root@db01 opt]# /usr/local/mysql5616/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql5616 --datadir=/data/5616/data
Can't locate Data/Dumper.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/mysql5616/scripts/mysql_install_db line 42.
BEGIN failed--compilation aborted at /usr/local/mysql5616/scripts/mysql_install_db line 42.
出现这个初始化错误的时候代表缺少一个per的插件.执行命令:
[root@db01 opt]# yum install 'perl(Data::Dumper)'
然后再进行初始化
[root@db01 opt]# /usr/local/mysql5616/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql5616 --datadir=/data/5616/data
Installing MySQL system tables...2021-07-04 02:34:59 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-07-04 02:34:59 8251 [Note] InnoDB: Using atomics to ref count buffer pool pages
2021-07-04 02:34:59 8251 [Note] InnoDB: The InnoDB memory heap is disabled
2021-07-04 02:34:59 8251 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-07-04 02:34:59 8251 [Note] InnoDB: Compressed tables use zlib 1.2.3
2021-07-04 02:34:59 8251 [Note] InnoDB: Using Linux native AIO
2021-07-04 02:34:59 8251 [Note] InnoDB: Using CPU crc32 instructions
2021-07-04 02:34:59 8251 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2021-07-04 02:34:59 8251 [Note] InnoDB: Completed initialization of buffer pool
2021-07-04 02:34:59 8251 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2021-07-04 02:34:59 8251 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2021-07-04 02:34:59 8251 [Note] InnoDB: Database physically writes the file full: wait...
2021-07-04 02:34:59 8251 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2021-07-04 02:34:59 8251 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2021-07-04 02:34:59 8251 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2021-07-04 02:34:59 8251 [Warning] InnoDB: New log files created, LSN=45781
2021-07-04 02:34:59 8251 [Note] InnoDB: Doublewrite buffer not found: creating new
2021-07-04 02:34:59 8251 [Note] InnoDB: Doublewrite buffer created
2021-07-04 02:34:59 8251 [Note] InnoDB: 128 rollback segment(s) are active.
2021-07-04 02:34:59 8251 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-07-04 02:34:59 8251 [Note] InnoDB: Foreign key constraint system tables created
2021-07-04 02:34:59 8251 [Note] InnoDB: Creating tablespace and datafile system tables.
2021-07-04 02:34:59 8251 [Note] InnoDB: Tablespace and datafile system tables created.
2021-07-04 02:34:59 8251 [Note] InnoDB: Waiting for purge to start
2021-07-04 02:34:59 8251 [Note] InnoDB: 5.6.16 started; log sequence number 0
2021-07-04 02:35:00 8251 [Note] Binlog end
2021-07-04 02:35:00 8251 [Note] InnoDB: FTS optimize thread exiting.
2021-07-04 02:35:00 8251 [Note] InnoDB: Starting shutdown...
2021-07-04 02:35:01 8251 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2021-07-04 02:35:01 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-07-04 02:35:01 8274 [Note] InnoDB: Using atomics to ref count buffer pool pages
2021-07-04 02:35:01 8274 [Note] InnoDB: The InnoDB memory heap is disabled
2021-07-04 02:35:01 8274 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-07-04 02:35:01 8274 [Note] InnoDB: Compressed tables use zlib 1.2.3
2021-07-04 02:35:01 8274 [Note] InnoDB: Using Linux native AIO
2021-07-04 02:35:01 8274 [Note] InnoDB: Using CPU crc32 instructions
2021-07-04 02:35:01 8274 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2021-07-04 02:35:01 8274 [Note] InnoDB: Completed initialization of buffer pool
2021-07-04 02:35:01 8274 [Note] InnoDB: Highest supported file format is Barracuda.
2021-07-04 02:35:01 8274 [Note] InnoDB: 128 rollback segment(s) are active.
2021-07-04 02:35:01 8274 [Note] InnoDB: Waiting for purge to start
2021-07-04 02:35:01 8274 [Note] InnoDB: 5.6.16 started; log sequence number 1625977
2021-07-04 02:35:01 8274 [Note] Binlog end
2021-07-04 02:35:01 8274 [Note] InnoDB: FTS optimize thread exiting.
2021-07-04 02:35:01 8274 [Note] InnoDB: Starting shutdown...
2021-07-04 02:35:03 8274 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
当看到上边出现两个OK的时候就代表初始化成功了

现在对MySQL5733进行初始化
[root@db01 opt]# /usr/local/mysql5733/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql5733 --datadir=/data/5733/data
2021-07-04T06:39:21.921546Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-07-04T06:39:22.547370Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-07-04T06:39:22.613516Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-07-04T06:39:22.672090Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9157d5c7-dc92-11eb-a479-000c29dfc6f4.
2021-07-04T06:39:22.675212Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-07-04T06:39:23.669684Z 0 [Warning] CA certificate ca.pem is self signed.
2021-07-04T06:39:24.018202Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
MySQL5733初始化成功

对MySQL8021进行初始化:
[root@db01 opt]# /usr/local/mysql8021/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql8021 --datadir=/data/8021/data
2021-07-04T06:41:09.105846Z 0 [System] [MY-013169] [Server] /usr/local/mysql8021/bin/mysqld (mysqld 8.0.21) initializing of server in progress as process 8326
2021-07-04T06:41:09.141094Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-07-04T06:41:11.039769Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-07-04T06:41:13.108039Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

3.2 启动各版本数据库

启动MySQL5616
/usr/local/mysql5616/bin/mysqld_safe --defaults-file=/data/5616/my.cnf &
启动MySQL5733
/usr/local/bin/mysqld_safe --defaults-file=/data/5733/my.cnf &
启动MySQL8021
/usr/local/bin/mysqld_safe --defaults-file=/data/8021/my.cnf &
查看多实例启动情况
[root@db01 mysql8021]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      6694/sshd           
tcp6       0      0 :::3306                 :::*                    LISTEN      11099/./bin/mysqld  
tcp6       0      0 :::3307                 :::*                    LISTEN      9767/mysqld         
tcp6       0      0 :::3308                 :::*                    LISTEN      11408/mysqld        
tcp6       0      0 :::22                   :::*                    LISTEN      6694/sshd           
tcp6       0      0 :::33060                :::*                    LISTEN      11408/mysqld        

3.3 启动过程错误解决


[root@db01 opt]# /usr/local/mysql5733/bin/mysqld 
2021-07-04T06:50:33.162662Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-07-04T06:50:33.162787Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2021-07-04T06:50:33.162827Z 0 [Note] /usr/local/mysql5733/bin/mysqld (mysqld 5.7.33) starting as process 8912 ...
2021-07-04T06:50:33.162871Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2021-07-04T06:50:33.164529Z 0 [Warning] Can't create test file /usr/local/mysql/data/db01.lower-test
2021-07-04T06:50:33.164560Z 0 [Warning] Can't create test file /usr/local/mysql/data/db01.lower-test
2021-07-04T06:50:33.164596Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

2021-07-04T06:50:33.164629Z 0 [ERROR] Aborting

2021-07-04T06:50:33.164662Z 0 [Note] Binlog end
2021-07-04T06:50:33.164732Z 0 [Note] 

这个错误是配置文件中有空格导致的.检查是否有空格
声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>