MySQL多实例部署

MySQL多实例部署


下载软件

[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# ls
debug  kernels  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# groupadd -r mysql
[root@localhost src]# useradd -M -s /sbin/nologin -g mysql mysql

解压安装

[root@localhost src]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

gzip: stdin: unexpected end of file
tar: Unexpected EOF in archive
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now
[root@localhost src]# ls /usr/local/
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.37-linux-glibc2.12-x86_64  sbin  share  src
[root@localhost src]# cd /usr/local/
[root@localhost local]# mv mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ll
total 0
drwxr-xr-x. 2 root root  6 Jun 21  2021 bin
drwxr-xr-x. 2 root root  6 Jun 21  2021 etc
drwxr-xr-x. 2 root root  6 Jun 21  2021 games
drwxr-xr-x. 2 root root  6 Jun 21  2021 include
drwxr-xr-x. 2 root root  6 Jun 21  2021 lib
drwxr-xr-x. 3 root root 17 Mar 22 19:07 lib64
drwxr-xr-x. 2 root root  6 Jun 21  2021 libexec
drwxr-xr-x  7 root root 68 Jul  2 10:23 mysql
drwxr-xr-x. 2 root root  6 Jun 21  2021 sbin
drwxr-xr-x. 5 root root 49 Mar 22 19:07 share
drwxr-xr-x. 2 root root  6 Jun 21  2021 src
[root@localhost local]# chown -R mysql.mysql /usr/local/mysql/
[root@localhost local]# ll -d /usr/local/mysql/
drwxr-xr-x 7 mysql mysql 68 Jul  2 10:23 /usr/local/mysql/

配置环境变量

[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# source /etc/profile.d/mysql.sh 
[root@localhost local]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@localhost local]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@localhost local]# ldconfig
[root@localhost local]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/local/mysql/man

创建各实例数据存放的目录

[root@localhost local]# mkdir -p /opt/data/{3306,3307,3308}
[root@localhost local]# chown -R mysql.mysql /opt/data/
[root@localhost local]# ll /opt/data/
total 0
drwxr-xr-x 2 mysql mysql 6 Jul  2 10:35 3306
drwxr-xr-x 2 mysql mysql 6 Jul  2 10:35 3307
drwxr-xr-x 2 mysql mysql 6 Jul  2 10:35 3308

初始化各实例

[root@localhost local]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2022-07-03T13:07:58.308334Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-03T13:07:58.507028Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-03T13:07:58.549280Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-03T13:07:58.612205Z 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: 2916f4fb-fad1-11ec-997e-000c29399951.
2022-07-03T13:07:58.613784Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-03T13:07:59.152386Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-03T13:07:59.152426Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-03T13:07:59.153244Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-03T13:07:59.211050Z 1 [Note] A temporary password is generated for root@localhost: ?gYMd&s>5SK4
[root@localhost local]# echo '?gYMd&s>5SK4' > /root/3306_pass


[root@localhost local]# mysqld --initialize --datadir=/opt/data/3307 --user=mysql
2022-07-03T13:08:32.652971Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-03T13:08:32.915621Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-03T13:08:32.958793Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-03T13:08:33.018190Z 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: 3d98e4c6-fad1-11ec-9a8a-000c29399951.
2022-07-03T13:08:33.019575Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-03T13:08:33.792318Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-03T13:08:33.792375Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-03T13:08:33.793200Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-03T13:08:34.168693Z 1 [Note] A temporary password is generated for root@localhost: _hBrhaNxE4Ye
[root@localhost local]# echo '_hBrhaNxE4Ye' > /root/3307_pass

安装所需的依赖包

[root@localhost local]# dnf -y install perl
[root@localhost local]# dnf -y install ncurses-compat-libs

写配置文件并启动

[root@localhost local]# vim /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

[root@localhost local]# mysqld_multi start 3306
[root@localhost local]# mysqld_multi start 3307
[root@localhost local]# mysqld_multi start 3308

[root@localhost local]# ss -antl
State       Recv-Q      Send-Q             Local Address:Port             Peer Address:Port      Process      
LISTEN      0           128                      0.0.0.0:22                    0.0.0.0:*                      
LISTEN      0           128                         [::]:22                       [::]:*                      
LISTEN      0           80                             *:3306                        *:*                      
LISTEN      0           80                             *:3307                        *:*                      
LISTEN      0           80                             *:3308                        *:*                      

初始化密码

[root@localhost ~]# cat 3306_pass 
?gYMd&s>5SK4
[root@localhost ~]# mysql -uroot -p'?gYMd&s>5SK4' -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.37

Copyright (c) 2000, 2022, 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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye



[root@localhost ~]# cat 3307_pass 
_hBrhaNxE4Ye
[root@localhost ~]# 
[root@localhost ~]# mysql -uroot -p'_hBrhaNxE4Ye' -S /tmp/mysql3307.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.37

Copyright (c) 2000, 2022, 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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye


[root@localhost ~]# cat 3308_pass 
M(sX(J/yD0jJ
[root@localhost ~]# mysql -uroot -p'M(sX(J/yD0jJ' -S /tmp/mysql3308.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.37

Copyright (c) 2000, 2022, 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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值