多实例部署的原因:多个项目并行时,如果有项目需要重启,其他项目有多实例的部署就不会收到影响,一个实例配套一个项目。(如果没有多实例部署,那么其他项目会受到影响)
多实例部署步骤:
先传安装包
开始部署
//创建用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
//解压软件至/usr/local/
[root@localhost ~]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
bin games lib libexec sbin src
etc include lib64 mysql-5.7.37-linux-glibc2.12-x86_64 share
//重命名
[root@localhost local]# mv mysql-5.7.37-linux-glibc2.12-x86_64 mysql
[root@localhost local]# ls
bin etc games include lib lib64 libexec mysql sbin share src
//修改目录/usr/local/mysql的属主属组
[root@localhost local]# chown -R mysql.mysql mysql/
[root@localhost local]# ll
total 0
drwxr-xr-x. 2 root root 6 Jun 21 2021 bin
drwxr-xr-x. 2 root root 6 Jun 21 2021 etc
drwxr-xr-x. 2 root root 6 Jun 21 2021 games
drwxr-xr-x. 2 root root 6 Jun 21 2021 include
drwxr-xr-x. 2 root root 6 Jun 21 2021 lib
drwxr-xr-x. 3 root root 17 Jun 30 20:15 lib64
drwxr-xr-x. 2 root root 6 Jun 21 2021 libexec
drwxr-xr-x. 9 mysql mysql 129 Jul 3 17:56 mysql
drwxr-xr-x. 2 root root 6 Jun 21 2021 sbin
drwxr-xr-x. 5 root root 49 Jun 30 20:15 share
drwxr-xr-x. 2 root root 6 Jun 21 2021 src
//配置环境变量
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# source /etc/profile.d/mysql.sh
[root@localhost local]# ls mysql/
bin docs include lib LICENSE man README share support-files
[root@localhost local]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@localhost local]# vi /etc/man_db.conf
#
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/mysql/man
[root@localhost local]# vi /etc/ld.so.conf.d/mysqld.conf
/usr/local/mysql/lib
[root@localhost local]# ldconfig
创建各实例数据存放的目录
[root@localhost ~]# mkdir -p /opt/data/{3306,3307,3308}
[root@localhost ~]# ls /opt/data/
3306 3307 3308
初始化各实例
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3306
2022-07-03T10:10:01.184564Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-03T10:10:01.352090Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-03T10:10:01.387810Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-03T10:10:01.459790Z 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: 4d02cab9-fab8-11ec-974f-000c294bf476.
2022-07-03T10:10:01.462141Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-03T10:10:02.081884Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-03T10:10:02.081897Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-03T10:10:02.082211Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-03T10:10:02.159045Z 1 [Note] A temporary password is generated for root@localhost: ejr1:4I8sp%0
[root@localhost ~]# echo 'ejr1:4I8sp%0' > 3306
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3307
2022-07-03T10:10:54.372187Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-03T10:10:54.570471Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-03T10:10:54.603452Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-03T10:10:54.658109Z 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: 6cb835da-fab8-11ec-9c0e-000c294bf476.
2022-07-03T10:10:54.658826Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-03T10:10:55.217349Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-03T10:10:55.217362Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Plea