mysq多实例部署与mysql主从

1. mysql多实例部署

软件下载

#下载二进制格式的mysql软件包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https:#downloads.mysql.com/archives/get/file/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@data1 src]# ls
debug  kernels  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz

安装perl 及初始化软件包

[root@localhost ~]# yum -y install perl  ncurses-compat-libs
Complete!
[root@data1 src]# 

配置用户和组并解压二进制程序至/usr/local下

#创建用户和组
[root@data1 src]# useradd -r -M -s  /sbin/nologin mysql 
[root@data1 src]# id mysql
uid=995(mysql) gid=992(mysql) groups=992(mysql)



#解压软件至/usr/local/ 
[root@data1 src]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@data1 src]# ls /usr/local/
bin  games    lib    libexec                              sbin   src
etc  include  lib64  mysql-5.7.37-linux-glibc2.12-x86_64  share

#创建软链接 直接改名也可以 
[root@data1 src]# cd /usr/local/
[root@data1 local]# mv mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
[root@data1 local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src


#修改目录/usr/local/mysql的属主属组
[root@data1 local]# ll .|grep mysql
drwxr-xr-x. 9 root root 129 Jul  2 09:14 mysql
[root@data1 local]# chown -R mysql.mysql /usr/local/mysql
[root@data1 local]# ll .|grep mysql
drwxr-xr-x. 9 mysql mysql 129 Jul  2 09:14 mysql

#配置环境变量
[root@data1 local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@data1 local]# source /etc/profile.d/mysql.sh
[root@data1 local]# which mysql
/usr/local/mysql/bin/mysql

创建各实例数据存放的目录并设置属组

[root@data1 local]# mkdir -p /opt/data/{1106,1107,1108}
[root@data1 local]# chown -R mysql.mysql /opt/data/
[root@data1 local]# ll /opt/data/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jul  2 09:19 1106
drwxr-xr-x. 2 mysql mysql 6 Jul  2 09:19 1107
drwxr-xr-x. 2 mysql mysql 6 Jul  2 09:19 1108

[root@data1 local]# tree /opt/data/
/opt/data/
├── 1106
├── 1107
└── 1108

3 directories, 0 files

初始化各实例

#初始化1106实例
[root@data1 local]# mysqld --initialize --datadir=/opt/data/1106 --user=mysql
2022-07-02T01:20:58.039448Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-02T01:20:58.172107Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-02T01:20:58.238859Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-02T01:20:58.295239Z 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: 3a328565-f9a5-11ec-9b7a-000c29922ca1.
2022-07-02T01:20:58.296104Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-02T01:20:58.987237Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-02T01:20:58.987261Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-02T01:20:58.987745Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-02T01:20:59.176963Z 1 [Note] A temporary password is generated for root@localhost: TcasGp3Oe+vL
#1106初始化临时密码写入文件
[root@data1 local]# echo 'TcasGp3Oe+vL' > /root/1106_passwd


[root@data1 local]# mysqld --initialize --datadir=/opt/data/1107 --user=mysql
2022-07-02T01:22:25.915303Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-02T01:22:26.033069Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-02T01:22:26.065443Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-02T01:22:26.124696Z 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: 6e8c3815-f9a5-11ec-9eef-000c29922ca1.
2022-07-02T01:22:26.131450Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-02T01:22:26.813296Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-02T01:22:26.813315Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-02T01:22:26.813756Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-02T01:22:26.843884Z 1 [Note] A temporary password is generated for root@localhost: #*Pun:zY/0!9
#1107初始化临时密码写入文件
[root@data1 local]# echo '#*Pun:zY/0!9' > /root/1107_passwd


[root@data1 local]# mysqld --initialize --datadir=/opt/data/1108 --user=mysql
2022-07-02T01:24:58.849157Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-02T01:24:58.965364Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-02T01:24:58.997060Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-02T01:24:59.052666Z 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: c9b33040-f9a5-11ec-a3be-000c29922ca1.
2022-07-02T01:24:59.053393Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-02T01:24:59.438702Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-02T01:24:59.438720Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-02T01:24:59.439081Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-02T01:24:59.666089Z 1 [Note] A temporary password is generated for root@localhost: Bk!,eUd.p3+Z
#1107初始化临时密码写入文件
[root@data1 local]# echo 'Bk!,eUd.p3+Z' > /root/1108_passwd

[root@data1 local]# cd
[root@data1 ~]# ls
1106_passwd  1107_passwd  1108_passwd  anaconda-ks.cfg

配置配置文件/etc/my.cnf

[root@localhost ~]# vim /etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin

[mysqld1106]
datadir = /opt/data/1106
port = 1106
socket = /tmp/mysql1106.sock
pid-file = /opt/data/1106/mysql_1106.pid
log-error=/var/log/1106.log

[mysqld1107]
datadir = /opt/data/1107
port = 1107
socket = /tmp/mysql1107.sock
pid-file = /opt/data/1107/mysql_1107.pid
log-error=/var/log/1107.log

[mysqld1108]
datadir = /opt/data/1108
port = 1108
socket = /tmp/mysql1108.sock
pid-file = /opt/data/1108/mysql_1108.pid
log-error=/var/log/1108.log

启动各实例

[root@data1 ~]# mysqld_multi start 1106
[root@data1 ~]# mysqld_multi start 1107
[root@data1 ~]# mysqld_multi start 1108
[root@data1 ~]# 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         80                       *:1106                   *:*                  
LISTEN    0         80                       *:1107                   *:*                  
LISTEN    0         80                       *:1108                   *:*                  
LISTEN    0         128                   [::]:22                  [::]:* 

初始化密码

#初始化1106密码
[root@data1 ~]# ls
1106_passwd  1107_passwd  1108_passwd  anaconda-ks.cfg
[root@data1 ~]# cat 1106_passwd 
TcasGp3Oe+vL
[root@data1 ~]# mysql -uroot -p'TcasGp3Oe+vL' -S /tmp/mysql1106.sock /需要用到套接字
[root@localhost ~]# mysql -uroot -p'Y=lJV79Rkx,d' -S /tmp/mysql1106.sock 
mysql: [Warning] Using a password on the command line interface can be insecure.

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.01 sec)

mysql> quit
Bye


#初始化1107密码
[root@
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值