mysql多实例部署

mysql多实例部署

软件下载

[root@lwq-client ~]# cd /usr/src/
[root@lwq-client src]# ls
debug  kernels  mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@lwq-client src]# cd
[root@lwq-client ~]# 

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

//创建用户和组
[root@lwq-client ~]# groupadd -r mysql
[root@lwq-client ~]# useradd -M -s /sbin/nologin -g mysql mysql

//解压软件至/usr/local
[root@lwq-client src]# ls
debug  kernels  mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@lwq-client src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@lwq-client src]# ls
debug  kernels  mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@lwq-client src]# cd /usr/local/
[root@lwq-client local]# ls
bin  games    lib    libexec                              sbin   src
etc  include  lib64  mysql-5.7.22-linux-glibc2.12-x86_64  share
[root@lwq-client local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
"mysql" -> "mysql-5.7.22-linux-glibc2.12-x86_64/"
[root@lwq-client local]# ll
总用量 0
drwxr-xr-x. 2 root root   6 3月  10 2016 bin
drwxr-xr-x. 2 root root   6 3月  10 2016 etc
drwxr-xr-x. 2 root root   6 3月  10 2016 games
drwxr-xr-x. 2 root root   6 3月  10 2016 include
drwxr-xr-x. 2 root root   6 3月  10 2016 lib
drwxr-xr-x. 2 root root   6 3月  10 2016 lib64
drwxr-xr-x. 2 root root   6 3月  10 2016 libexec
lrwxrwxrwx. 1 root root  36 8月  19 10:25 mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 8月  19 10:24 mysql-5.7.22-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 3月  10 2016 sbin
drwxr-xr-x. 5 root root  49 7月  20 01:10 share
drwxr-xr-x. 2 root root   6 3月  10 2016 src

//修改/usr/local/mysql的属组属组
[root@lwq-client local]# chown -R mysql.mysql /usr/local/mysql
[root@lwq-client local]# ll -d /usr/local/mysql
lrwxrwxrwx. 1 mysql mysql 36 8月  19 10:25 /usr/local/mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/

//配置环境变量
[root@lwq-client ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@lwq-client ~]# . /etc/profile.d/mysql.sh 
[root@lwq-client ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

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

[root@lwq-client ~]# mkdir -p /opt/data/{3306,3307,3308}
[root@lwq-client ~]# chown -R mysql.mysql /opt/data/
[root@lwq-client ~]# ll /opt/data/
总用量 0
drwxr-xr-x. 2 mysql mysql 6 8月  19 10:32 3306
drwxr-xr-x. 2 mysql mysql 6 8月  19 10:32 3307
drwxr-xr-x. 2 mysql mysql 6 8月  19 10:32 3308

[root@lwq-client ~]# yum -y install tree
[root@lwq-client ~]# tree /opt/data/
/opt/data/
├── 3306
├── 3307
└── 3308

3 directories, 0 files

初始化各实例

//初始化3306实例
[root@lwq-client ~]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2019-08-19T02:38:05.198072Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-19T02:38:05.461387Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-19T02:38:05.520051Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-19T02:38:05.578159Z 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: 5f5bdc74-c22a-11e9-b95e-000c29b10852.
2019-08-19T02:38:05.578956Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-19T02:38:05.579787Z 1 [Note] A temporary password is generated for root@localhost: f16p+M(3yip4
[root@lwq-client ~]# echo 'f16p+M(3yip4' > 3306
[root@lwq-client ~]# cat 3306
f16p+M(3yip4

//初始化3307实例
[root@lwq-client ~]# mysqld --initialize --datadir=/opt/data/3307 --user=mysql
2019-08-19T02:42:00.670652Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-19T02:42:01.536789Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-19T02:42:01.581895Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-19T02:42:01.638243Z 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: ec0fc565-c22a-11e9-8178-000c29b10852.
2019-08-19T02:42:01.658200Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-19T02:42:01.659373Z 1 [Note] A temporary password is generated for root@localhost: 2F1su>bsprZ%
[root@lwq-client ~]# echo '2F1su>bsprZ%' > 3307
[root@lwq-client ~]# cat 3307
2F1su>bsprZ%

//初始化3308实例
[root@lwq-client ~]# mysqld --initialize --datadir=/opt/data/3308 --user=mysql
2019-08-19T02:43:33.071868Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-19T02:43:33.416574Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-19T02:43:33.461321Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-19T02:43:33.516636Z 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: 22d34d4e-c22b-11e9-86fd-000c29b10852.
2019-08-19T02:43:33.517589Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-19T02:43:33.519590Z 1 [Note] A temporary password is generated for root@localhost: hSY:.&FRO6kq
[root@lwq-client ~]# echo 'hSY:.&FRO6kq' > 3308
[root@lwq-client ~]# cat 3308
hSY:.&FRO6kq

安装perl

[root@lwq-client ~]# yum -y install perl

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

[root@lwq-client ~]# vim /etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/muysql/bin/mysqladmin
#user = root                             //以下两行可以注释
#password = lwq

[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@lwq-client ~]# mysqld_multi start 3306
[root@lwq-client ~]# mysqld_multi start 3307
[root@lwq-client ~]# mysqld_multi start 3308
[root@lwq-client ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128               *:111                           *:*                  
LISTEN      0      5      192.168.122.1:53                            *:*                  
LISTEN      0      128               *:22                            *:*                  
LISTEN      0      128       127.0.0.1:631                           *:*                  
LISTEN      0      100       127.0.0.1:25                            *:*                  
LISTEN      0      128       127.0.0.1:6010                          *:*                  
LISTEN      0      80               :::3307                         :::*                  
LISTEN      0      80               :::3308                         :::*                  
LISTEN      0      128              :::111                          :::*                  
LISTEN      0      128              :::22                           :::*                  
LISTEN      0      128             ::1:631                          :::*                  
LISTEN      0      100             ::1:25                           :::*                  
LISTEN      0      128             ::1:6010                         :::*                  
LISTEN      0      80               :::3306                         :::*        

初始化密码

//初始化3306密码
[root@lwq-client ~]# ls
3306  3308  3307  anaconda-ks.cfg  
[root@lwq-client ~]# cat 3306
f16p+M(3yip4
[root@lwq-client ~]# mysql -uroot -p'f16p+M(3yip4' -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.22

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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('lwq');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> exit
Bye
//用修改的密码登陆
[root@lwq-client ~]# mysql -uroot -plwq -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 3
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> exit
Bye

[root@lwq-client ~]# mysql -uroot -plwq -h 127.0.0.1 -P 3306
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 5
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> 



//初始化3307密码
[root@lwq-client ~]# cat 3307
2F1su>bsprZ%
[root@lwq-client ~]# mysql -uroot -p'2F1su>bsprZ%' -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.22

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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('lwq');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye
//用修改的密码登陆
[root@lwq-client ~]# mysql -uroot -plwq -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 3
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> exit
Bye


//初始化3308密码
[root@lwq-client ~]# cat 3308
hSY:.&FRO6kq
[root@lwq-client ~]# mysql -uroot -p'hSY:.&FRO6kq' -S /tmp/mysql3308.sock -e 'set password = password("lwq");' --connect-expired-password
mysql: [Warning] Using a password on the command line interface can be insecure.
//用修改的密码登陆
[root@lwq-client ~]# mysql -uroot -plwq -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 3
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值