//創建用戶和組[root@localhost src]# groupadd -r mysql
[root@localhost src]# useradd -M -s /sbin/nologin -g mysql mysql
//解壓軟件至/usr/local/[root@localhost src]# ls
debug kernels mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/[root@localhost ~]# ls /usr/local/
bin games lib libexec sbin src
etc include lib64 mysql-5.7.22-linux-glibc2.12-x86_64 share
[root@localhost ~]# cd /usr/local/[root@localhost local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
‘mysql’ -> ‘mysql-5.7.22-linux-glibc2.12-x86_64/’
[root@localhost local]# ll
total 0
drwxr-xr-x.2 root root 6Mar102016 bin
drwxr-xr-x.2 root root 6Mar102016 etc
drwxr-xr-x.2 root root 6Mar102016 games
drwxr-xr-x.2 root root 6Mar102016 include
drwxr-xr-x.2 root root 6Mar102016 lib
drwxr-xr-x.2 root root 6Mar102016 lib64
drwxr-xr-x.2 root root 6Mar102016 libexec
lrwxrwxrwx 1 root root 36Aug1416:00 mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
drwxr-xr-x 9 root root 129Aug1400:16 mysql-5.7.22-linux-glibc2.12-x86_64
drwxr-xr-x.2 root root 6Mar102016 sbin
drwxr-xr-x.5 root root 49Jun1319:03 share
drwxr-xr-x.2 root root 6Mar102016 src
//修改目錄/usr/local/mysql的屬主屬組[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
[root@localhost ~]# ll /usr/local/mysql -d
lrwxrwxrwx 1 mysql mysql 36Aug1416:00/usr/local/mysql -> mysql-5.7.22-linux-glibc2.12-x86_64///配置環境變量[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH'>/etc/profile.d/mysql.sh
[root@localhost ~]# ./etc/profile.d/mysql.sh
[root@localhost ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
創建各實例數據存放的目錄
[root@localhost ~]# mkdir -p /opt/data/{3306,3307,3308}[root@localhost ~]# chown -R mysql.mysql /opt/data/[root@localhost ~]# ll /opt/data/
總用量 0
drwxr-xr-x 2 mysql mysql 65月 921:243306
drwxr-xr-x 2 mysql mysql 65月 921:243307
drwxr-xr-x 2 mysql mysql 65月 921:243308[root@localhost ~]# tree /opt/data//opt/data/
├── 3306
├── 3307
└── 33083 directories,0 files
初始化各實例
//初始化3306實例[root@localhost ~]# mysqld --initialize --datadir=/opt/data/3306--user=mysql
2019-05-10T01:43:33.987463Z 0[Warning]TIMESTAMP with implicitDEFAULTvalueis deprecated.Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2019-05-10T01:43:34.565759Z 0[Warning] InnoDB:New log files created, LSN=457902019-05-10T01:43:34.733540Z 0[Warning] InnoDB:Creating foreign key constraint system tables.2019-05-10T01:43:34.808595Z 0[Warning]No existing UUID has been found, so we assume that thisis the first time that this server has been started.Generating a newUUID:061b480e-72c5-11e9-ae30-000c29c0ed3b.2019-05-10T01:43:34.810131Z 0[Warning]Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2019-05-10T01:43:34.837499Z 1[Note]A temporary password is generated for root@localhost: Y=lJV79Rkx,d
[root@localhost ~]# echo 'Y=lJV79Rkx,d'>3306_pass
//初始化3307實例[root@localhost ~]# mysqld --initialize --datadir=/opt/data/3307--user=mysql
2019-05-10T01:45:41.206120Z 0[Warning]TIMESTAMP with implicitDEFAULTvalueis deprecated.Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2019-05-10T01:45:42.082891Z 0[Warning] InnoDB:New log files created, LSN=457902019-05-10T01:45:42.258639Z 0[Warning] InnoDB:Creating foreign key constraint system tables.2019-05-10T01:45:42.352269Z 0[Warning]No existing UUID has been found, so we assume that thisis the first time that this server has been started.Generating a newUUID:5220e72b-72c5-11e9-b195-000c29c0ed3b.2019-05-10T01:45:42.353339Z 0[Warning]Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2019-05-10T01:45:42.354494Z 1[Note]A temporary password is generated for root@localhost: bpG+yqeGN8G:[root@localhost ~]# echo 'bpG+yqeGN8G:'>3307_pass
//初始化3308實例[root@localhost ~]# mysqld --initialize --datadir=/opt/data/3308--user=mysql
2019-05-10T01:46:52.707755Z 0[Warning]TIMESTAMP with implicitDEFAULTvalueis deprecated.Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2019-05-10T01:46:53.546346Z 0[Warning] InnoDB:New log files created, LSN=457902019-05-10T01:46:53.732779Z 0[Warning] InnoDB:Creating foreign key constraint system tables.2019-05-10T01:46:53.810767Z 0[Warning]No existing UUID has been found, so we assume that thisis the first time that this server has been started.Generating a newUUID:7cb89aad-72c5-11e9-b5a1-000c29c0ed3b.2019-05-10T01:46:53.813509Z 0[Warning]Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2019-05-10T01:46:53.815051Z 1[Note]A temporary password is generated for root@localhost: wior7yf:1Awu
[root@localhost ~]# echo 'wior7yf:1Awu'>3308_pass
安裝perl
[root@localhost ~]# yum -y install perl
配置配置文件/etc/my.cnf
[root@localhost ~]# 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
[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@localhost ~]# ls
3306_pass 3307_pass 3308_pass anaconda-ks.cfg
[root@localhost ~]# cat 3306_pass
Y=lJV79Rkx,d
[root@localhost ~]# mysql -uroot -p'Y=lJV79Rkx,d'-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.YourMySQL connection id is3Server version:5.7.22
Copyright (c)2000,2018,Oracle and/or its affiliates.All rights reserved.Oracleis a registered trademark of OracleCorporation 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('wangqing123!');Query OK,0 rows affected,1 warning (0.01 sec)
mysql> quit
Bye
[root@localhost ~]# cat 3307_pass
bpG+yqeGN8G:[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 3308_pass
wior7yf:1Awu
[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.