下载mysql源码包
[root@test ~]# ls
anaconda-ks.cfg mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
配置用户和组并解压二进制程序至/usr/local下
[root@test ~]# useradd -r -M -s /sbin/nologin mysql
[root@test ~]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@test ~]# cd /usr/local/
[root@test local]# ln -s mysql-5.7.31-linux-glibc2.12-x86_64 mysql
[root@test local]# chown -R mysql.mysql mysql*
[root@test local]# ll
total 0
drwxr-xr-x. 2 root root 6 May 11 2019 bin
drwxr-xr-x. 2 root root 6 May 11 2019 etc
drwxr-xr-x. 2 root root 6 May 11 2019 games
drwxr-xr-x. 2 root root 6 May 11 2019 include
drwxr-xr-x. 2 root root 6 May 11 2019 lib
drwxr-xr-x. 2 root root 6 May 11 2019 lib64
drwxr-xr-x. 2 root root 6 May 11 2019 libexec
lrwxrwxrwx. 1 mysql mysql 35 Jan 4 20:15 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64
drwxr-xr-x. 9 mysql mysql 129 Jun 2 2020 mysql-5.7.31-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 May 11 2019 sbin
drwxr-xr-x. 5 root root 49 Dec 14 23:39 share
drwxr-xr-x. 2 root root 6 May 11 2019 src
[root@test local]# cd
[root@test ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@test ~]# source /etc/profile.d/mysql.sh
[root@test ~]# which mysql
/usr/local/mysql/bin/mysql
创建存放数据的目录
[root@test ~]# mkdir -p /opt/data/{3306,3307,3308}
[root@test ~]# chown -R mysql.mysql /opt/data/
[root@test ~]# ll /opt/data/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jan 4 20:17 3306
drwxr-xr-x. 2 mysql mysql 6 Jan 4 20:17 3307
drwxr-xr-x. 2 mysql mysql 6 Jan 4 20:17 3308
安装依赖包
[root@test ~]# yum -y install ncurses-compat-libs
初始化3306、3307、3308
[root@test ~]# mysqld --initialize --user=mysql --datadir=/opt/data/3306
2021-01-04T12:17:45.223723Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-01-04T12:17:45.475339Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-01-04T12:17:45.517735Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-01-04T12:17:45.572175Z 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: da0bc89e-4e86-11eb-97c6-000c2989b3b5.
2021-01-04T12:17:45.573172Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-01-04T12:17:47.402280Z 0 [Warning] CA certificate ca.pem is self signed.
2021-01-04T12:17:47.995096Z 1 [Note] A temporary password is generated for root@localhost: dEbjxFf
[root@test ~]# echo 'dEbjxFf
dEbjxFf
[root@test ~]# echo 'dEbjxFf 3306
[root@test ~]# mysqld --initialize --user=mysql --datadir=/opt/data/3307
2021-01-04T12:19:07.570471Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-01-04T12:19:07.760903Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-01-04T12:19:07.803646Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-01-04T12:19:07.859749Z 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: 0b17defa-4e87-11eb-9aaa-000c2989b3b5.
2021-01-04T12:19:07.860627Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-01-04T12:19:08.687627Z 0 [Warning] CA certificate ca.pem is self signed.
2021-01-04T12:19:08.785218Z 1 [Note] A temporary password is generated for root@localhost: rr4qSYlqDh(o
[root@test ~]# echo 'rr4qSYlqDh(o' > 3307
[root@test ~]# mysqld --initialize --user=mysql --datadir=/opt/data/3308
2021-01-04T12:19:52.278019Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-01-04T12:19:52.469220Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-01-04T12:19:52.509314Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-01-04T12:19:52.564968Z 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: 25bd589a-4e87-11eb-9d83-000c2989b3b5.
2021-01-04T12:19:52.565782Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-01-04T12:19:53.403824Z 0 [Warning] CA certificate ca.pem is self signed.
2021-01-04T12:19:53.642059Z 1 [Note] A temporary password is generated for root@localhost: Rg#-4gffRo,Q
[root@test ~]# echo 'Rg#-4gffRo,Q' > 3308
[root@test ~]# ls
3306 3307 3308 anaconda-ks.cfg mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
安装perl
[root@localhost ~]# yum -y install perl
写配置文件my.cnf
[root@test ~]# 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@test ~]# mysqld_multi start 3306
[root@test ~]# mysqld_multi start 3307
[root@test ~]# mysqld_multi start 3308
[root@test ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]😗
LISTEN 0 80 *:3306 :
LISTEN 0 80 *:3307 :
LISTEN 0 80 *:3308 :
设置密码
[root@test ~]# cat 3306
dEbjxFf
[root@test ~]# mysql -uroot -p'dEbjxFf
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation 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 ('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
[root@test ~]# cat 3307
rr4qSYlqDh(o
[root@test ~]# mysql -uroot -p'rr4qSYlqDh(o'
mysql> set password = password('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
[root@test ~]# mysql -uroot -p'123' -S /tmp/mysql3307.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql> quit
Bye
[root@test ~]# cat 3308
Rg#-4gffRo,Q
[root@test ~]# mysql -uroot -p'Rg#-4gffRo,Q'
mysql> set password = password('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
[root@test ~]# mysql -uroot -p'123' -S /tmp/mysql3308.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql> quit
Bye