软件下载
//下载二进制格式的mysql软件包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
--2021-11-07 14:22:15-- https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
正在解析主机 downloads.mysql.com (downloads.mysql.com)... 137.254.60.14
正在连接 downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz [跟随至新的 URL]
--2021-11-07 14:22:18-- https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
正在解析主机 cdn.mysql.com (cdn.mysql.com)... 2.18.233.231
正在连接 cdn.mysql.com (cdn.mysql.com)|2.18.233.231|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:665389778 (635M) [application/x-tar-gz]
正在保存至: “mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz”
mysql-5.7.34-linux-glibc2 100%[===================================>] 634.56M 704KB/s 用时 14m 16s
2021-11-07 14:36:38 (759 KB/s) - 已保存 “mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz” [665389778/665389778])
[root@localhost src]#
配置用户和组并解压二进制程序至/usr/local下
//创建用户和组
[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.34-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# ls /usr/local/
bin etc games include lib lib64 libexec mysql-5.7.34-linux-glibc2.12-x86_64 sbin share src
[root@localhost src]# cd /usr/local/
[root@localhost local]# ln -s mysql-5.7.34-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 2 root root 6 8月 12 2018 bin
drwxr-xr-x. 2 root root 6 8月 12 2018 etc
drwxr-xr-x. 2 root root 6 8月 12 2018 games
drwxr-xr-x. 2 root root 6 8月 12 2018 include
drwxr-xr-x. 2 root root 6 8月 12 2018 lib
drwxr-xr-x. 2 root root 6 8月 12 2018 lib64
drwxr-xr-x. 2 root root 6 8月 12 2018 libexec
lrwxrwxrwx 1 root root 36 11月 7 14:42 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64/
drwxr-xr-x 9 root root 129 11月 7 14:40 mysql-5.7.34-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 8月 12 2018 sbin
drwxr-xr-x. 5 root root 49 9月 30 09:11 share
drwxr-xr-x. 2 root root 6 8月 12 2018 src
[root@localhost local]#
//修改目录/usr/local/mysql的属主属组
[root@localhost local]# chown -R mysql.mysql /usr/local/mysql
[root@localhost local]# ll /usr/local/mysql
//配置环境变量
[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]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost local]# which mysql
/usr/local/mysql/bin/mysql
[root@localhost local]#
创建各实例数据存放的目录
[root@localhost local]# mkdir -p /opt/data/{3306,3307,3308}
[root@localhost local]# chown mysql.mysql /opt/data/{3306,3307,3308}
[root@localhost local]# cd /opt/data/
[root@localhost data]# ll
总用量 0
drwxr-xr-x 2 mysql mysql 6 11月 7 14:47 3306
drwxr-xr-x 2 mysql mysql 6 11月 7 14:47 3307
drwxr-xr-x 2 mysql mysql 6 11月 7 14:47 3308
[root@localhost data]# cd
初始化各实例
//初始化3306
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/3306
2021-11-07T06:54:48.103068Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-11-07T06:54:48.211635Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-11-07T06:54:48.230370Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-11-07T06:54:48.235850Z 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: 991228a6-3f97-11ec-9ff0-000c29b91252.
2021-11-07T06:54:48.236353Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-11-07T06:54:48.822771Z 0 [Warning] CA certificate ca.pem is self signed.
2021-11-07T06:54:49.222888Z 1 [Note] A temporary password is generated for root@localhost: 2&ie7sfG.aOa
[root@localhost ~]# echo '2&ie7sfG.aOa' > 3306_pass
[root@localhost ~]# cat 3306_pass
2&ie7sfG.aOa
//初始化3307
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/3307
2021-11-07T06:56:11.802336Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-11-07T06:56:12.466590Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-11-07T06:56:12.655912Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-11-07T06:56:12.689396Z 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: cb68bf34-3f97-11ec-a466-000c29b91252.
2021-11-07T06:56:12.690954Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-11-07T06:56:13.146813Z 0 [Warning] CA certificate ca.pem is self signed.
2021-11-07T06:56:13.249333Z 1 [Note] A temporary password is generated for root@localhost: QQw_wQeat7wv
[root@localhost ~]# echo 'QQw_wQeat7wv' > 3307_pass
[root@localhost ~]# cat 3307_pass
QQw_wQeat7wv
//初始化3308
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/3308
2021-11-07T06:57:28.136080Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-11-07T06:57:32.910652Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-11-07T06:57:33.083388Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-11-07T06:57:33.171827Z 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: fb616436-3f97-11ec-a742-000c29b91252.
2021-11-07T06:57:33.172679Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-11-07T06:57:34.413641Z 0 [Warning] CA certificate ca.pem is self signed.
2021-11-07T06:57:34.779236Z 1 [Note] A temporary password is generated for root@localhost: yhl/Rh2tEPI.
[root@localhost ~]# echo 'yhl/Rh2tEPI.' > 3308_pass
[root@localhost ~]# cat 3308_pass
yhl/Rh2tEPI.
[root@localhost ~]#
//安装perl
[root@localhost ~]# yum -y install perl
//ldd是看某一个程序文件它所依赖的包,如果没有,就不能用,就需要用yum安装,查找哪个包提供的yum whatprovides pkgs_name
[root@localhost ~]# ldd /usr/local/mysql/bin/mysql
linux-vdso.so.1 (0x00007ffdcd95c000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff4c766e000)
librt.so.1 => /lib64/librt.so.1 (0x00007ff4c7465000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007ff4c7261000)
libncurses.so.5 => not found
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007ff4c6ecc000)
libm.so.6 => /lib64/libm.so.6 (0x00007ff4c6b4a000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007ff4c6932000)
libc.so.6 => /lib64/libc.so.6 (0x00007ff4c6570000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff4c788e000)
libtinfo.so.5 => not found
[root@localhost ~]# yum whatprovides libtinfo.so.5
[root@localhost ~]# yum -y install ncurses-compat-libs
//配置配置文件/etc/my.cnf
[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cat /etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
[mysqld3306]
datadir = /opt/data/3306
socket = /tmp/mysql3306.sock
port = 3306
pid-file = /opt/data/3306/mysql_3306.pid
log-error = /var/log/3306.log
[mysqld3307]
datadir = /opt/data/3307
socket = /tmp/mysql3307.sock
port = 3307
pid-file = /opt/data/3307/mysql_3307.pid
log-error = /var/log/3307.log
[mysqld3308]
datadir = /opt/data/3308
socket = /tmp/mysql3308.sock
port = 3308
pid-file = /opt/data/3308/mysql_3308.pid
log-error = /var/log/3308.log
[root@localhost ~]#
//启动各实例
[root@localhost ~]# mysqld_multi start
Wide character in print at /usr/local/mysql/bin/mysqld_multi line 678.
[root@localhost ~]# 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@localhost ~]#
//修改临时密码密码
[root@localhost ~]# cat 3306_pass
2&ie7sfG.aOa
[root@localhost ~]# mysql -uroot -p'2&ie7sfG.aOa' -P3306 -h127.0.0.1
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 3
Server version: 5.7.34
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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('1');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit
Bye
[root@localhost ~]# cat 3307_pass
QQw_wQeat7wv
[root@localhost ~]# mysql -uroot -p'QQw_wQeat7wv' -P3307 -h127.0.0.1
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.34
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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('1');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit
Bye
[root@localhost ~]# cat 3308_pass
yhl/Rh2tEPI.
[root@localhost ~]# mysql -uroot -p'yhl/Rh2tEPI.' -P3308 -h127.0.0.1
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.34
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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('1');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit
Bye
多实例设置服务:
停止MySQL服务用 pkill mysqld , 启动服务用 /usr/local/mysql/support-files/mysqld_multi.server start
1.设置开机自启 :把 /usr/local/mysql/bin/support.files/mysqld_multi.server 文件复制到 /etc/init.d/mysqld.server
[root@localhost ~]# cd /etc/init.d/
[root@localhost init.d]# cp /usr/local/mysql/support-files/mysqld_multi.server ./mysqld.server
[root@localhost init.d]# ls
functions mysqld.server README
[root@localhost init.d]#
2. 在/etc/init.d/mysqld.server 文件中增加环境变量设置 export PATH=/usr/local/mysql/bin: $PATH
[root@localhost init.d]# vim mysqld.server
16 export PATH=/usr/local/mysql/bin/:$PATH //添加环境变量
3. chkconfig --add mysqld.server
[root@localhost init.d]# chkconfig --add mysqld.server
[root@localhost init.d]# chkconfig --list
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
mysqld.server 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@localhost init.d]#