目录
- 1.软件下载
- 2.配置用户和组并解压二进制程序至/usr/local下
- 3.创建各实例数据存放的目录
- 4.初始化各示例
- 5.配置配置文件/etc/my.cnf
- 6.启动各示例
- 7.使用system控制启动
- 8.初始化密码
1.软件下载
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
--2022-07-29 13:28:14-- https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
Resolving cdn.mysql.com (cdn.mysql.com)... 23.2.84.230
Connecting to cdn.mysql.com (cdn.mysql.com)|23.2.84.230|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 674830866 (644M) [application/x-tar-gz]
Saving to: \'mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz\'
mysql-5.7.38-linux-glibc2.12-x 100%[==================================================>] 643.57M 3.35MB/s in 4m 15s
2022-07-29 13:32:30 (2.52 MB/s) - \'mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz\' saved [674830866/674830866]
[root@localhost src]# ls
debug kernels mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
2.配置用户和组并解压二进制程序至/usr/local下
[root@localhost src]# useradd -M -r -s /sbin/nologin mysql
[root@localhost src]# id mysql
uid=995(mysql) gid=992(mysql) groups=992(mysql)
[root@localhost src]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# cd
[root@localhost ~]# ls /usr/local/
bin etc games include lib lib64 libexec mysql-5.7.38-linux-glibc2.12-x86_64 sbin share src
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -sv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
\'mysql\' -> \'mysql-5.7.38-linux-glibc2.12-x86_64\'
[root@localhost local]# ll
total 0
drwxr-xr-x. 2 root root 6 Jun 22 2021 bin
drwxr-xr-x. 2 root root 6 Jun 22 2021 etc
drwxr-xr-x. 2 root root 6 Jun 22 2021 games
drwxr-xr-x. 2 root root 6 Jun 22 2021 include
drwxr-xr-x. 2 root root 6 Jun 22 2021 lib
drwxr-xr-x. 3 root root 17 Jul 12 21:45 lib64
drwxr-xr-x. 2 root root 6 Jun 22 2021 libexec
lrwxrwxrwx. 1 root root 35 Jul 29 13:39 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 9 root root 129 Jul 29 13:38 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 Jun 22 2021 sbin
drwxr-xr-x. 5 root root 49 Jul 12 21:45 share
drwxr-xr-x. 2 root root 6 Jun 22 2021 src
//修改目录/usr/local/mysql的属主属组
[root@localhost local]# chown -R mysql.mysql mysql*
[root@localhost local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 35 Jul 29 13:39 /usr/local/mysql -> mysql-5.7.38-linux-glibc2.12-x86_64
//配置环境变量
[root@localhost local]# echo \'export PATH=$PATH:/usr/local/mysql/bin\' > /etc/profile.d/mysql.sh
[root@localhost local]# source /etc/profile.d/mysql.sh
[root@localhost local]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
//创建头文件
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# ls
LICENSE README bin docs include lib man share support-files
[root@localhost mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql //配置软链接
\'/usr/include/mysql\' -> \'/usr/local/mysql/include/\'
[root@localhost ~]# chown -R mysql.mysql /usr/include/mysql
[root@localhost ~]# ll -d /usr/include/mysql
lrwxrwxrwx. 1 mysql mysql 25 Jul 29 14:37 /usr/include/mysql -> /usr/local/mysql/include/
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib/
[root@localhost ~]# ldconfig
[root@localhost ~]# vim /etc/man_db.conf
#MANDATORY_MANPATH /usr/src/pvm3/man
#
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/mysql/man //添加一行
3.创建各实例数据存放的目录
[root@localhost ~]# mkdir -p /opt/data/{3306,3307,3308}
[root@localhost ~]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# ll /opt/data/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jul 29 13:45 3306
drwxr-xr-x. 2 mysql mysql 6 Jul 29 13:45 3307
drwxr-xr-x. 2 mysql mysql 6 Jul 29 13:45 3308
[root@localhost ~]# tree /opt/data/
/opt/data/
|-- 3306
|-- 3307
`-- 3308
4.初始化各示例
//初始化3306
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3306
2022-07-29T05:48:04.206397Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-29T05:48:04.369296Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-29T05:48:04.403256Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-29T05:48:04.462960Z 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: 03b0e61e-0f02-11ed-b4ce-000c296d5362.
2022-07-29T05:48:04.464340Z 0 [Warning] Gtid table is not ready to be used. Table \'mysql.gtid_executed\' cannot be opened.
2022-07-29T05:48:04.643259Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T05:48:04.643284Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T05:48:04.643585Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-29T05:48:04.717924Z 1 [Note] A temporary password is generated for root@localhost: ,dASzpwwE3RJ
[root@localhost ~]# echo \',dASzpwwE3RJ\' > 3306
[root@localhost ~]# ls
3306 anaconda-ks.cfg
//初始化3307
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3307
2022-07-29T05:49:29.037700Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-29T05:49:29.195218Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-29T05:49:29.224130Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-29T05:49:29.281903Z 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: 363f3e1c-0f02-11ed-8fdd-000c296d5362.
2022-07-29T05:49:29.283175Z 0 [Warning] Gtid table is not ready to be used. Table \'mysql.gtid_executed\' cannot be opened.
2022-07-29T05:49:29.523082Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T05:49:29.523118Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T05:49:29.523503Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-29T05:49:29.581009Z 1 [Note] A temporary password is generated for root@localhost: )MhldlF<o23j
[root@localhost ~]# echo \')MhldlF<o23j\' > 3307
[root@localhost ~]# ls
3306 3307 anaconda-ks.cfg
//初始化3308
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3308
2022-07-29T05:50:14.735254Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-29T05:50:14.892190Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-29T05:50:14.915269Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-29T05:50:14.973272Z 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: 517b3121-0f02-11ed-a3f6-000c296d5362.
2022-07-29T05:50:14.974697Z 0 [Warning] Gtid table is not ready to be used. Table \'mysql.gtid_executed\' cannot be opened.
2022-07-29T05:50:15.340479Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T05:50:15.340510Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T05:50:15.341068Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-29T05:50:15.368072Z 1 [Note] A temporary password is generated for root@localhost: tkdnhiEk>5vh
[root@localhost ~]# echo \'tkdnhiEk>5vh\' > 3308
[root@localhost ~]# ls
3306 3307 3308 anaconda-ks.cfg
5.配置配置文件/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
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
6.启动各示例
[root@localhost ~]# mysqld_multi start 3306
-bash: /usr/local/mysql/bin/mysqld_multi: /usr/bin/perl: bad interpreter: No such file or directory //需要下载perl包
[root@localhost ~]# dnf -y install perl
[root@localhost mysql]# yum install ncurses-compat-libs
[root@localhost mysql]# file /usr/local/mysql/bin/mysqld_multi
/usr/local/mysql/bin/mysqld_multi: Perl script text executable
[root@localhost ~]# mysqld_multi start 3306
[root@localhost ~]# mysqld_multi start 3307
[root@localhost ~]# mysqld_multi start 3308
[root@localhost ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3308 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 80 *:3307 *:*
7.使用system控制启动
//需要先把mysql服务停止 //mysqld_mulit 命令停止不了只能杀进程
[root@localhost ~]# ps -ef | grep 3306 | grep -v grep
root 77016 1 0 13:55 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data/3306 --port=3306 --socket=/tmp/mysql3306.sock --pid-file=/opt/data/3306/mysql_3306.pid --log-error=/var/log/3306.log
mysql 77152 77016 0 13:55 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data/3306 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/3306.log --pid-file=/opt/data/3306/mysql_3306.pid --socket=/tmp/mysql3306.sock --port=3306
[root@localhost ~]# ps -ef | grep 3306 | grep -v grep | awk \'{print$2}\'
77016
77152
[root@localhost ~]# ps -ef | grep 3306 | grep -v grep | awk \'{print$2}\' | xargs kill -9
[root@localhost ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3308 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3307 *:*
[root@localhost ~]# ps -ef | grep 3307 | grep -v grep | awk \'{print$2}\' | xargs kill -9
[root@localhost ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3308 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@localhost ~]# ps -ef | grep 3308 | grep -v grep | awk \'{print$2}\' | xargs kill -9
[root@localhost ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
//找个一个系统默认可以使用system控制的配置文件进行cp一下,并进行修改
[root@localhost ~]# cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/3306.service
//配置3306
[root@localhost ~]# vim /usr/lib/systemd/system/3306.service
[Unit]
Description=3306 server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/bin/mysqld_multi start 3306
ExecStop=ps -ef | grep 3306 | grep -v grep | awk \'{print$2}\' | xargs kill -9
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
//配置3307
[root@localhost ~]# cp /usr/lib/systemd/system/3306.service /usr/lib/systemd/system/3307.service
[root@localhost ~]# vim /usr/lib/systemd/system/3307.service //使用:% s/6/7/g一键替换
[Unit]
Description=3307 server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/bin/mysqld_multi start 3307
ExecStop=ps -ef | grep 3307 | grep -v grep | awk \'{print$2}\' | xargs kill -9
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
//配置3308
[root@localhost ~]# cp /usr/lib/systemd/system/3306.service /usr/lib/systemd/system/3308.service
[root@localhost ~]# vim /usr/lib/systemd/system/3308.service //使用:% s/6/7/g一键替换
[Unit]
Description=3308 server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/bin/mysqld_multi start 3308
ExecStop=ps -ef | grep 3308 | grep -v grep | awk \'{print$2}\' | xargs kill -9
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
//刷新一下
[root@localhost ~]# systemctl daemon-reload
//关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
//启动3306,3307,3308
[root@localhost ~]# systemctl start 3306
Job for 3306.service failed because the control process exited with error code.
See \"systemctl status 3306.service\" and \"journalctl -xe\" for details. //没有找到my_print_defaults这个文件
//创建一个软链接到/usr/bin下
[root@localhost ~]# ln -s /usr/local/mysql/bin/my_print_defaults /usr/bin/my_print_defaults
[root@localhost ~]# systemctl start 3306
[root@localhost ~]# systemctl start 3307
[root@localhost ~]# systemctl start 3308
[root@localhost ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3308 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 80 *:3307 *:*
8.初始化密码
//3306
[root@localhost ~]# mysql -uroot -p\',dASzpwwE3RJ\' -S /tmp/mysql.sock
mysql> set password = password(\'123456\');
Query OK, 0 rows affected, 1 warning (0.00 sec)
//3307
[root@localhost ~]# mysql -uroot -p\')MhldlF<o23j\' -S /tmp/mysql3307.sock
mysql> set password = password(\'123456\');
Query OK, 0 rows affected, 1 warning (0.00 sec)
//3308
[root@localhost ~]# mysql -uroot -p\'tkdnhiEk>5vh\' -S /tmp/mysql3308.sock
mysql> set password = password(\'123456\');
Query OK, 0 rows affected, 1 warning (0.00 sec)
来源:https://www.cnblogs.com/Their-own/p/16532585.html
本站部分图文来源于网络,如有侵权请联系删除。