mysql多实例部署

软件下载

 1 #下载
 2 [root@zwy1 ~]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
 3 #提前安装
 4 #解压
 5 [root@zwy1 ~]# ls
 6 all-210508.sql nginx-1.18.0 Percona-XtraBackup-2.4.22-rc99a781-el8-x86_64-bundle.tar percona-xtrabackup-24-debugsource-2.4.22-1.el8.x86_64.rpm
 7 anaconda-ks.cfg nginx-1.18.0.tar.gz percona-xtrabackup-24-2.4.22-1.el8.x86_64.rpm percona-xtrabackup-test-24-2.4.22-1.el8.x86_64.rpm
 8 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz pass percona-xtrabackup-24-debuginfo-2.4.22-1.el8.x86_64.rpm percona-xtrabackup-test-24-debuginfo-2.4.22-1.el8.x86_64.rpm
 9 [root@zwy1 ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
10 #创建用户和组
11 [root@zwy1 ~]# groupadd -r mysql
12 [root@zwy1 ~]# useradd -M -s /sbin/nologin -g mysql mysql

软链接映射

 1 [root@zwy1 local]# ln -sv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
 2 'mysql/mysql-5.7.33-linux-glibc2.12-x86_64' -> 'mysql-5.7.33-linux-glibc2.12-x86_64/'
 3 [root@zwy1 local]# ll
 4 total 0
 5 drwxr-xr-x. 2 root  root    6 Nov  3  2020 bin
 6 drwxr-xr-x. 2 root  root    6 Nov  3  2020 etc
 7 drwxr-xr-x. 2 root  root    6 Nov  3  2020 games
 8 drwxr-xr-x. 2 root  root    6 Nov  3  2020 include
 9 drwxr-xr-x. 2 root  root    6 Nov  3  2020 lib
10 drwxr-xr-x. 3 root  root   17 Mar  8 17:19 lib64
11 drwxr-xr-x. 2 root  root    6 Nov  3  2020 libexec
12 lrwxrwxrwx. 1 mysql mysql  47 May  8 00:57 mysql -> /usr/local/mysql-5.7.33-linux-glibc2.12-x86_64/
13 drwxr-xr-x. 9 mysql mysql 172 May 10 20:12 mysql-5.7.33-linux-glibc2.12-x86_64
14 drwxr-xr-x. 2 root  root    6 Nov  3  2020 sbin
15 drwxr-xr-x. 5 root  root   49 Mar  8 17:19 share
16 drwxr-xr-x. 2 root  root    6 Nov  3  2020 src

修改目标属主和属组

chown -R mysql.mysql /usr/local/mysql #修改

[root@zwy1 local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 47 May  8 00:57 /usr/local/mysql -> /usr/local/mysql-5.7.33-linux-glibc2.12-x86_64/

配置环境变量

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

创建实例存放目录

[root@zwy1 local]# mkdir /opt/data/{3306,3307,3308}
[root@zwy1 ~]# chown -R mysql.mysql /opt/data/

初始化DB

#初始化实例
[root@zwy1 local]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2021-05-10T12:30:52.985449Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-10T12:30:53.514042Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-10T12:30:53.560028Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-10T12:30:53.618235Z 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: 8fce91ff-b18b-11eb-b796-000c29dd2233.
2021-05-10T12:30:53.618702Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-10T12:30:53.823936Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-10T12:30:54.091177Z 1 [Note] A temporary password is generated for root@localhost: <dl:iq/sd8Rc
[root@zwy1 local]# echo '<dl:iq/sd8Rc' > 06pass

 

[root@zwy1 local]# mysqld --initialize --datadir=/opt/data/3307 --user=mysql
2021-05-10T12:33:30.247964Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-10T12:33:30.665956Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-10T12:33:30.692835Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-10T12:33:30.750842Z 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: ed771a91-b18b-11eb-bc0a-000c29dd2233.
2021-05-10T12:33:30.751256Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-10T12:33:31.177165Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-10T12:33:31.349837Z 1 [Note] A temporary password is generated for root@localhost: QcdR2QYNtb,%
[root@zwy1 local]# echo 'QcdR2QYNtb,%' > 07pass

安装perl

dnf -y install perl

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

[root@zwy1~]# 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

启动各项

[root@localhost ~]# mysqld_multi start 3306
[root@localhost ~]# mysqld_multi start 3307

初始化密码

[root@localhost ~]# cat 07pass
QcdR2QYNtb,%
[root@localhost ~]# mysql -uroot -p'bpG+yqeGN8G:' -S /tmp/mysql3307.sock -e 'set password = password("wangqing123!");' --connect-expired-password
mysql: [Warning] Using a password on the command line interface can be insecure.


[root@localhost ~]# cat 06pass

<dl:iq/sd8Rc

[root@localhost ~]# mysql -uroot -p'wior7yf:1Awu' -S /tmp/mysql3308.sock -e 'set password = password("wangqing123!");' --connect-expired-password mysql: [Warning] Using a password on the command line interface can be insecure.

 

posted @ 2021-05-10 22:52  #44  阅读(58)  评论(0)    收藏  举报