MySQL多实例部署
MySQL二进制安装
下载文件传输(可有可无)
[root@server3 src]# yum -y install lrzsz
Failed to set locale, defaulting to C.UTF-8
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
......
......
......
Installed:
lrzsz-0.12.20-43.el8.x86_64
Complete!
下载MySQL安装包
https://downloads.mysql.com/archives/community/
传输软件
[root@server3 ~]# cd /usr/src/
[root@server3 src]# rz
[root@server3 src]# ls
debug mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
kernels
解压软件包到指定目录
[root@server3 src]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@server3 src]# cd /usr/local/
[root@server3 local]# ls
bin lib sbin
etc lib64 share
games libexec src
include mysql-5.7.34-linux-glibc2.12-x86_64
[root@server3 local]# ll
创建用户
[root@server3 src]# useradd -r -M -s /sbin/nologin mysql
[root@server3 src]# grep mysql /etc/group
mysql:x:989:
[root@server3 src]#
创建软连接
[root@server3 local]# ln -sv mysql-5.7.34-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.34-linux-glibc2.12-x86_64/'
[root@server3 local]# ll
total 0
drwxr-xr-x. 2 root root 6 Aug 12 2018 bin
drwxr-xr-x. 2 root root 6 Aug 12 2018 etc
drwxr-xr-x. 2 root root 6 Aug 12 2018 games
drwxr-xr-x. 2 root root 6 Aug 12 2018 include
drwxr-xr-x. 2 root root 6 Aug 12 2018 lib
drwxr-xr-x. 2 root root 6 Aug 12 2018 lib64
drwxr-xr-x. 2 root root 6 Aug 12 2018 libexec
lrwxrwxrwx. 1 root root 36 Aug 29 14:33 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 Aug 29 14:31 mysql-5.7.34-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 Aug 12 2018 sbin
drwxr-xr-x. 5 root root 49 Jul 18 11:10 share
drwxr-xr-x. 2 root root 6 Aug 12 2018 src
更改软连接和MySQL文件的属主和属组
[root@server3 local]# chown -R mysql.mysql mysql*
[root@server3 local]# ll
total 0
drwxr-xr-x. 2 root root 6 Aug 12 2018 bin
drwxr-xr-x. 2 root root 6 Aug 12 2018 etc
drwxr-xr-x. 2 root root 6 Aug 12 2018 games
drwxr-xr-x. 2 root root 6 Aug 12 2018 include
drwxr-xr-x. 2 root root 6 Aug 12 2018 lib
drwxr-xr-x. 2 root root 6 Aug 12 2018 lib64
drwxr-xr-x. 2 root root 6 Aug 12 2018 libexec
lrwxrwxrwx. 1 mysql mysql 36 Aug 29 14:33 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 mysql mysql 129 Aug 29 14:31 mysql-5.7.34-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 Aug 12 2018 sbin
drwxr-xr-x. 5 root root 49 Jul 18 11:10 share
drwxr-xr-x. 2 root root 6 Aug 12 2018 src
配置环境变量
[root@server3 local]# cd /etc/profile.d/
[root@server3 profile.d]# ls
colorgrep.csh colorzgrep.sh less.sh
colorgrep.sh csh.local sh.local
colorls.csh gawk.csh vim.csh
colorls.sh gawk.sh vim.sh
colorxzgrep.csh lang.csh which2.csh
colorxzgrep.sh lang.sh which2.sh
colorzgrep.csh less.csh
[root@server3 profile.d]# vim mysql.sh
[root@server3 profile.d]# cat mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@server3 profile.d]# ls
colorgrep.csh colorzgrep.sh less.sh
colorgrep.sh csh.local mysql.sh
colorls.csh gawk.csh sh.local
colorls.sh gawk.sh vim.csh
colorxzgrep.csh lang.csh vim.sh
colorxzgrep.sh lang.sh which2.csh
colorzgrep.csh less.csh which2.sh
[root@server3 ~]# . /etc/profile.d/mysql.sh
[root@server3 ~]#
[root@server3 ~]# which mysqld
/usr/local/mysql/bin/mysqld
[root@server3 ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
创建数据存放目录并更改属主和属组
[root@server3 local]# mkdir -p /opt/data/{3306,3307,3308}
[root@server3 opt]# tree data/
data/
|-- 3306
|-- 3307
`-- 3308
[root@server3 opt]# chown -R mysql.mysql data/
[root@server3 opt]# ll
total 0
drwxr-xr-x. 5 mysql mysql 42 Aug 29 14:37 data
[root@server3 opt]#cd data/
[root@server3 data]# ll
total 0
drwxr-xr-x. 2 mysql mysql 6 Aug 29 14:37 3306
drwxr-xr-x. 2 mysql mysql 6 Aug 29 14:37 3307
drwxr-xr-x. 2 mysql mysql 6 Aug 29 14:37 3308
初始化
//初始化3306
[root@server3 ~]# mysqld --initialize --user mysql --datadir /opt/data/3306
2021-08-29T06:59:31.993679Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-08-29T06:59:32.243463Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-08-29T06:59:32.288516Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-08-29T06:59:32.349180Z 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: a97fe963-0896-11ec-9d06-000c29b7b58b.
2021-08-29T06:59:32.350197Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-08-29T06:59:32.579028Z 0 [Warning] CA certificate ca.pem is self signed.
2021-08-29T06:59:32.634237Z 1 [Note] A temporary password is generated for root@localhost: Xj?p1xvr5usN
[root@server3 ~]# echo 'Xj?p1xvr5usN' > 3306_passwd //存储临时密码
[root@server3 ~]# ls
3306_passwd anaconda-ks.cfg
[root@server3 ~]# cat 3306_passwd
Xj?p1xvr5usN
//初始化3307
[root@server3 ~]# mysqld --initialize --user mysql --datadir /opt/data/3307
2021-08-29T07:04:15.972752Z 0 [Warning] TIMESTAMP with impli