mysql多实例部署

mysql多实例部署

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

[root@controller ~]# service mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@controller ~]# 
[root@controller ~]# rm -rf /opt/data/*
[root@controller ~]# ls /opt/data/
[root@controller ~]# 
[root@controller ~]# mkdir -p /opt/data/{3306,3307,3308}
[root@controller ~]# ls /opt/data/                      
3306  3307  3308
[root@controller ~]# 
[root@controller ~]# chown -R mysql.mysql /opt/data/
[root@controller ~]# ll /opt/data/                  
total 0
drwxr-xr-x 2 mysql mysql 6 Sep  5 20:57 3306
drwxr-xr-x 2 mysql mysql 6 Sep  5 20:57 3307
drwxr-xr-x 2 mysql mysql 6 Sep  5 20:57 3308
[root@controller ~]# 

初始化各实例

[root@controller ~]# mysqld --insecure-initialize --user=mysql --datadir=/opt/data/3306 
...
2023-09-05T13:01:57.854140Z 0 [Note] Shutting down plugin 'sha256_password'
2023-09-05T13:01:57.854142Z 0 [Note] Shutting down plugin 'mysql_native_password'
2023-09-05T13:01:57.854224Z 0 [Note] Shutting down plugin 'binlog'
2023-09-05T13:01:57.854313Z 0 [Note] mysqld: Shutdown complete
[root@controller ~]#
[root@controller ~]# mysqld --insecure-initialize --user=mysql --datadir=/opt/data/3307
...
2023-09-05T13:03:31.593893Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2023-09-05T13:03:31.593896Z 0 [Note] Shutting down plugin 'sha256_password'
2023-09-05T13:03:31.593897Z 0 [Note] Shutting down plugin 'mysql_native_password'
2023-09-05T13:03:31.593982Z 0 [Note] Shutting down plugin 'binlog'
2023-09-05T13:03:31.594066Z 0 [Note] mysqld: Shutdown complete
[root@controller ~]# 
[root@controller ~]# mysqld --insecure-initialize --user=mysql --datadir=/opt/data/3308
...
2023-09-05T13:04:24.611408Z 0 [Note] Shutting down plugin 'sha256_password'
2023-09-05T13:04:24.611412Z 0 [Note] Shutting down plugin 'mysql_native_password'
2023-09-05T13:04:24.611674Z 0 [Note] Shutting down plugin 'binlog'
2023-09-05T13:04:24.611953Z 0 [Note] mysqld: Shutdown complete
[root@controller ~]# 
[root@controller ~]# ls /opt/data/*
/opt/data/3306:
ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1  mysql_bin.index

/opt/data/3307:
ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1  mysql_bin.index

/opt/data/3308:
ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1  mysql_bin.index
[root@controller ~]# 

安装perl

[root@controller ~]# yum -y install perl
...                             
  qt5-srpm-macros-5.15.2-1.el8.noarch                               redhat-rpm-config-125-1.el8.noarch             
  rust-srpm-macros-5-2.el8.noarch                                   systemtap-sdt-devel-4.5-3.el8.x86_64          
  unzip-6.0-45.el8_4.x86_64                                         zip-3.0-23.el8.x86_64                           
Complete!
[root@controller ~]#

配置/etc/my.cnf文件

配置前先将之前的my.cnf覆盖掉

[root@controller ~]# > /etc/my.cnf 
[root@controller ~]# 
[root@controller ~]# 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

启动各实例

启动前先将3306 ,3307 ,3308里的文件删除,不然会失败

[root@controller ~]# rm -rf /opt/data/3306/*
[root@controller ~]# mysqld_multi start 3306
...
2023-09-05T13:29:35.665669Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2023-09-05T13:29:35.666046Z 0 [Warning] CA certificate ca.pem is self signed.
2023-09-05T13:29:35.746833Z 1 [Note] A temporary password is generated for root@localhost: a,8UuPeY5XB>
[root@controller ~]# 
[root@controller ~]# echo 'a,8UuPeY5XB>' > 3306
[root@controller ~]# 
[root@controller ~]# rm -rf /opt/data/3307/*   
[root@controller ~]# 
[root@controller ~]# mysqld_multi start 3307
...
2023-09-05T13:31:08.775253Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2023-09-05T13:31:08.775569Z 0 [Warning] CA certificate ca.pem is self signed.
2023-09-05T13:31:08.861775Z 1 [Note] A temporary password is generated for root@localhost: VYKe4t<reTUX
[root@controller ~]# 
[root@controller ~]# echo 'VYKe4t<reTUX' > 3307
[root@controller ~]# 
[root@controller ~]# rm -rf /opt/data/3308/*
[root@controller ~]# 
[root@controller ~]# mysqld_multi start 3308
...
2023-09-05T13:31:43.156614Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2023-09-05T13:31:43.157234Z 0 [Warning] CA certificate ca.pem is self signed.
2023-09-05T13:31:43.284977Z 1 [Note] A temporary password is generated for root@localhost: &jdCZMq3!%kf
[root@controller ~]# 
[root@controller ~]# echo '&jdCZMq3!%kf' > 3308            
[root@controller ~]# 
[root@controller ~]# ss -anlt
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@controller ~]# 

初始化密码

给3306 ,3307 ,3308设置新的密码

[root@controller ~]# ls
3306  3307  3308  all-202309051036.sql  all-2023-9-5.sql  anaconda-ks.cfg  pass  table-2023-9-5.sql  xingge.sql
[root@controller ~]# 
[root@controller ~]# cat 3306
a,8UuPeY5XB>
[root@controller ~]# 
[root@controller ~]# mysql -uroot -p'a,gUyFdSa67<' -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.
...
mysql> 
mysql> set password = password('huangtianen!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> 
mysql> quit;
Bye
[root@controller ~]# 
[root@controller ~]# cat 3307
VYKe4t<reTUX
[root@controller ~]# 
[root@controller ~]# mysql -uroot -p'IdJsO>ui' -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.
...
mysql> 
mysql> set password = password('huangtianen!');      
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> 
mysql> quit;
Bye
[root@controller ~]# 
[root@controller ~]# cat 3308
&jdCZMq3!%kf
[root@controller ~]# 
[root@controller ~]# mysql -uroot -p'IhfKTRY%' -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.
...
mysql> 
mysql> set password = password('huangtianen!');    
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> 
mysql> quit;
Bye
[root@controller ~]# 

登录mysql验证

[root@controller ~]# mysql -uroot -huangtianen! -h127.0.0.1 -P3306     
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 6
...
mysql> 
mysql> quit;
Bye
[root@controller ~]# 
[root@controller ~]# mysql -uroot -huangtianen! -h127.0.0.1 -P3307
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 7
...
mysql> 
mysql> quit;
Bye
[root@controller ~]# 
[root@controller ~]# mysql -uroot -huangtianen! -h127.0.0.1 -P3308   
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 3
...
mysql> 
mysql> quit;
Bye
[root@controller ~]# 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值