mysql多实例部署
多实例部署
软件下载
[root@dzc ~]# cd /usr/src/
[root@dzc src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
--2021-08-30 02:17:55-- https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
正在解析主机 cdn.mysql.com (cdn.mysql.com)... 184.50.240.231
正在连接 cdn.mysql.com (cdn.mysql.com)|184.50.240.231|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:376537503 (359M) [application/x-tar-gz]
正在保存至: “mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz”
mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz 100%[=======================================================================================================>] 359.09M 2.45MB/s 用时 3m 3s
2021-08-30 02:20:59 (1.97 MB/s) - 已保存 “mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz” [376537503/376537503])
配置用户和组并解压二进制程序至/usr/local下
//创建用户和组
[root@dzc src]# groupadd -r mysql
[root@dzc src]# useradd -M -s /sbin/nologin -g mysql mysql
//解压软件至/usr/local/
[root@dzc src]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@dzc src]# ls /usr/local/
bin etc games include lib lib64 libexec mysql-5.7.31-linux-glibc2.12-x86_64 sbin share src
[root@dzc src]# cd /usr/local/
[root@dzc local]# ln -sv mysql-5.7.31-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.31-linux-glibc2.12-x86_64/'
[root@dzc local]# ll
总用量 0
drwxr-xr-x. 2 root root 6 8月 12 2018 bin
drwxr-xr-x. 2 root root 6 8月 12 2018 etc
drwxr-xr-x. 2 root root 6 8月 12 2018 games
drwxr-xr-x. 2 root root 6 8月 12 2018 include
drwxr-xr-x. 2 root root 6 8月 12 2018 lib
drwxr-xr-x. 2 root root 6 8月 12 2018 lib64
drwxr-xr-x. 2 root root 6 8月 12 2018 libexec
lrwxrwxrwx. 1 root root 36 8月 30 02:25 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 7161 31415 129 6月 2 2020 mysql-5.7.31-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 8月 12 2018 sbin
drwxr-xr-x. 5 root root 49 3月 1 14:54 share
drwxr-xr-x. 2 root root 6 8月 12 2018 src
//修改目录/usr/local/mysql的属主属组
[root@dzc local]# chown -R mysql.mysql /usr/local/mysql
[root@dzc local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 8月 30 02:25 /usr/local/mysql -> mysql-5.7.31-linux-glibc2.12-x86_64/
//配置环境变量
[root@dzc local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@dzc local]# . /etc/profile.d/mysql.sh
[root@dzc local]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
创建各实例数据存放的目录
[root@dzc local]# mkdir -p /opt/data/{3306,3307,3308}
[root@dzc local]# chown -R mysql.mysql /opt/data/
[root@dzc local]# ll /opt/data/
总用量 0
drwxr-xr-x. 2 mysql mysql 6 8月 30 02:26 3306
drwxr-xr-x. 2 mysql mysql 6 8月 30 02:26 3307
drwxr-xr-x. 2 mysql mysql 6 8月 30 02:26 3308
[root@dzc local]# tree /opt/data/
/opt/data/
├── 3306
├── 3307
└── 3308
初始化各实例
[root@dzc local]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2021-08-29T18:27:24.840446Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-08-29T18:27:25.053957Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-08-29T18:27:25.093902Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-08-29T18:27:25.100450Z 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: c1f9f735-08f6-11ec-9889-000c29dd789e.
2021-08-29T18:27:25.102085Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-08-29T18:27:25.789984Z 0 [Warning] CA certificate ca.pem is self signed.
2021-08-29T18:27:25.848182Z 1 [Note] A temporary password is generated for root@localhost: vYmi;FvHt9;>
[root@dzc local]# echo 'vYmi;FvHt9;>' > 3306_pass
[root@dzc local]# mysqld --initialize --datadir=/opt/data/3307 --user=mysql
2021-08-29T18:28:49.368669Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-08-29T18:28:49.609033Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-08-29T18:28:49.645483Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-08-29T18:28:49.649113Z 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: f45f1233-08f6-11ec-b2f9-000c29dd789e.
2021-08-29T18:28:49.649753Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-08-29T18:28:51.009141Z 0 [Warning] CA certificate ca.pem is self signed.
2021-08-29T18:28:51.087026Z 1 [Note] A temporary password is generated for root@localhost: OE+.rn!H8sMi
[root@dzc local]# echo ' OE+.rn!H8sMi' > 3307_pass
[root@dzc local]# mysqld --initialize --datadir=/opt/data/3308 --user=mysql
2021-08-29T18:29:26.294495Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-08-29T18:29:26.500331Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-08-29T18:29:26.537648Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-08-29T18:29:26.543413Z 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: 0a5cb1be-08f7-11ec-b793-000c29dd789e.
2021-08-29T18:29:26.544326Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-08-29T18:29:27.122843Z 0 [Warning] CA certificate ca.pem is self signed.
2021-08-29T18:29:27.432640Z 1 [Note] A temporary password is generated for root@localhost: NoZ+Cjg8mjyL
[root@dzc local]# echo ' NoZ+Cjg8mjyL' > 3308_pass
安装perl
[root@dzc local]# yum -y install perl
配置配置文件/etc/my.cnf
[root@dzc local]# vim /etc/my.cnf
[root@dzc local]# cat /etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
[mysqld3306]
datadir = /opt/data/3306
port = 3306
socket = /tmp/mysql3306.sock
pid-file = /opt/data/3306/mysql_3306.pid
log-error=/var/log/3306.log
[][mysqld3307]
datadir = /opt/data/3307
port = 3307
socket = /tmp/mysql3307.sock
pid-file = /opt/data/3307/mysql_3307.pid
log-error=/var/log/3307.log
[][mysqld3308]
datadir = /opt/data/3308
port = 3308
socket = /tmp/mysql3308.sock
pid-file = /opt/data/3308/mysql_3308.pid
log-error=/var/log/3308.log
启动3306、3307、3308实例
[root@dzc local]# mysqld_multi start 3306
Wide character in print at /usr/local/mysql/bin/mysqld_multi line 678.
[root@dzc local]# mysqld_multi start 3307
Wide character in print at /usr/local/mysql/bin/mysqld_multi line 678.
[root@dzc local]# mysqld_multi start 3308
Wide character in print at /usr/local/mysql/bin/mysqld_multi line 678.
[root@dzc local]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 80 *:3307 *:* LISTEN 0 80 *:3308 *:*
初始化密码
[root@dzc local]# ls
3306_pass 3307_pass 3308_pass bin etc games include lib lib64 libexec mysql mysql-5.7.31-linux-glibc2.12-x86_64 sbin share src
[root@wxy ~]# mysql -uroot -p'vYmi;FvHt9;>' -S /tmp/mysql3306.sock
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 2
Server version: 5.7.31
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.
mysql> set password = password('1');
Query OK, 0 rows affected, 1 warning (0.01 sec)
//3307与3308同上
开机自启:
多实例设置开机自启
1、把/usr/local/mysql/bin/support_files/mysqld_multi.service文件复制到/etc/init.d/mysqld_multi
2、在/etc/init.d/mysqld_multi文件中增加环境变量设置exoprt PATH=/usr/local/mysql/bin:$PATH
3、chkconfig --add mysqld_multi
评论区