#创建用户和组
[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
#初始化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@