文章目录
第二十四天
MySQL
mysql多实例部署
//下载二进制格式的MySQL软件包
[root@fuwuduan src]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
--2022-07-29 10:29:01-- https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
正在解析主机 cdn.mysql.com (cdn.mysql.com)... 23.194.211.12
正在连接 cdn.mysql.com (cdn.mysql.com)|23.194.211.12|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:674830866 (644M) [application/x-tar-gz]
正在保存至: “mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz”
mysql-5.7.38 100% 643.57M 26.7MB/s 用时 23s
2022-07-29 10:29:25 (27.6 MB/s) - 已保存 “mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz” [674830866/674830866])
[root@fuwuduan src]# ls
debug mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
kernels
//创建用户和组
[root@fuwuduan src]# useradd -r -M -s /sbin/nologin mysql
[root@fuwuduan src]# id mysql
uid=975(mysql) gid=974(mysql) 组=974(mysql)
//解压软件包至/usr/local/
[root@fuwuduan src]# ls
debug mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
kernels
[root@fuwuduan src]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
//添加环境变量
[root@fuwuduan local]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
//给MySQl安装包做一个软链接
[root@fuwuduan local]# 'mysql' -> 'mysql-5.7.38-linux-glibc2.12-x86_64/'
[root@fuwuduan local]# ll
总用量 0
drwxr-xr-x. 2 root root 6 6月 22 2021 bin
drwxr-xr-x. 2 root root 6 6月 22 2021 etc
drwxr-xr-x. 2 root root 6 6月 22 2021 games
drwxr-xr-x. 2 root root 6 6月 22 2021 include
drwxr-xr-x. 2 root root 6 6月 22 2021 lib
drwxr-xr-x. 3 root root 17 7月 11 14:41 lib64
drwxr-xr-x. 2 root root 6 6月 22 2021 libexec
lrwxrwxrwx. 1 root root 36 7月 29 10:42 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 7月 29 10:32 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 6月 22 2021 sbin
drwxr-xr-x. 5 root root 49 7月 11 14:41 share
drwxr-xr-x. 2 root root 6 6月 22 2021 src
//修改目录/usr/local/mysql的属主属组
[root@fuwuduan local]# chown -R mysql.mysql mysql
[root@fuwuduan local]# chown -R mysql.mysql mysql-5.7.38-linux-glibc2.12-x86_64/
[root@fuwuduan local]# ll
总用量 0
drwxr-xr-x. 2 root root 6 6月 22 2021 bin
drwxr-xr-x. 2 root root 6 6月 22 2021 etc
drwxr-xr-x. 2 root root 6 6月 22 2021 games
drwxr-xr-x. 2 root root 6 6月 22 2021 include
drwxr-xr-x. 2 root root 6 6月 22 2021 lib
drwxr-xr-x. 3 root root 17 7月 11 14:41 lib64
drwxr-xr-x. 2 root root 6 6月 22 2021 libexec
lrwxrwxrwx. 1 mysql mysql 36 7月 29 10:42 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 mysql mysql 129 7月 29 10:32 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 6月 22 2021 sbin
drwxr-xr-x. 5 root root 49 7月 11 14:41 share
drwxr-xr-x. 2 root root 6 6月 22 2021 src
//配置include头文件
[root@fuwuduan mysql]# ln -s /usr/local/mysql/include/ /usr/include/mysql
//配置lib文件
[root@fuwuduan mysql]# ls
bin include LICENSE README support-files
docs lib man share
[root@fuwuduan mysql]# vim /etc/ld.so.conf.d/mysql.conf
[root@fuwuduan mysql]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@fuwuduan mysql]# ldconfig
[root@fuwuduan mysql]# ls
bin include LICENSE README support-files
docs lib man share
[root@fuwuduan mysql]# vim /etc/ld.so.conf.d/mysql.conf
[root@fuwuduan mysql]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@fuwuduan mysql]# ldconfig
//配置man文件
[root@fuwuduan mysql]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/local/mysql/man
//建立数据存放目录
[root@fuwuduan mysql]# mkdir -p /opt/data/{3306,3307,3308}
[root@fuwuduan mysql]# chown -R mysql.mysql /opt/data/
[root@fuwuduan mysql]# ll /opt/data
总用量 0
drwxr-xr-x. 2 mysql mysql 6 7月 29 10:55 3306
drwxr-xr-x. 2 mysql mysql 6 7月 29 10:55 3307
drwxr-xr-x. 2 mysql mysql 6 7月 29 10:55 3308
//初始化数据库
//初始化3306实例
[root@localhost ~]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2019-05-10T01:43:33.987463Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is 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=45790
2019-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 this is the first time that this server has been started. Generating a new UUID: 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 implicit DEFAULT value is 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=45790
2019-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 this is the first time that this server has been started. Generating a new UUID: 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 implicit DEFAULT value is 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=45790
2019-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 this is the first time that this server has been started. Generating a new UUID: 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 ~]# mysqld_multi start 3306
[root@localhost ~]# mysqld_multi start 3307
[root@localhost ~]# mysqld_multi start 3308
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 80 :::3307 :::*
LISTEN 0 80 :::3308 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306
初始化密码
[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.
Your MySQL connection id is 3
Server version: 5.7.22
Copyright (c) 2000, 2018, 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('123456');
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> quit
Bye
rs.
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