MySQL多实例部署

 

二进制安装mysql

[root@localhost ~]# dnf install -y wget vim
CentOS Stream 8 - AppStream           7.9 kB/s | 4.4 kB     00:00    
CentOS Stream 8 - AppStream           7.7 MB/s | 8.5 MB     00:01    
CentOS Stream 8 - BaseOS              5.9 kB/s | 3.9 kB     00:00    
CentOS Stream 8 - BaseOS              619 kB/s | 2.7 MB     00:04    
CentOS Stream 8 - Extras              2.1 kB/s | 1.5 kB     00:00    
软件包 wget-1.19.5-10.el8.x86_64 已安装。
软件包 vim-enhanced-2:8.0.1763-15.el8.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!
[root@localhost ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
--2021-05-10 05:53:43--  https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.33-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.33-linux-glibc2.12-x86_64.tar.gz [跟随至新的 URL]
--2021-05-10 05:53:44--  https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
正在解析主机 cdn.mysql.com (cdn.mysql.com)... 104.97.24.228
正在连接 cdn.mysql.com (cdn.mysql.com)|104.97.24.228|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:661718255 (631M) [application/x-tar-gz]
正在保存至: “mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz”

mysql-5.7.33-linu 100%[===========>] 631.06M  7.07MB/s  用时 88s     

2021-05-10 05:55:14 (7.14 MB/s) - 已保存 “mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz” [661718255/661718255])

创建用户会自动生成组
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
[root@localhost ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local
[root@localhost ~]# cd /usr/local
[root@localhost local]#  mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ls
apache  apr-util  etc    include  lib64    mysql  share
apr     bin       games  lib      libexec  sbin   src

修改目录/usr/local/mysql的属主属组
[root@localhost local]# chown -R mysql.mysql /usr/local/mysql/
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 13 root  root  152 4月  27 07:01 apache
drwxr-xr-x.  6 root  root   58 4月  27 06:53 apr
drwxr-xr-x.  5 root  root   43 4月  27 06:54 apr-util
drwxr-xr-x.  2 root  root    6 5月  18 2020 bin
drwxr-xr-x.  2 root  root    6 5月  18 2020 etc
drwxr-xr-x.  2 root  root    6 5月  18 2020 games
drwxr-xr-x.  2 root  root    6 5月  18 2020 include
drwxr-xr-x.  2 root  root    6 5月  18 2020 lib
drwxr-xr-x.  3 root  root   17 4月  25 19:59 lib64
drwxr-xr-x.  2 root  root    6 5月  18 2020 libexec
drwxr-xr-x.  9 mysql mysql 129 5月  10 05:56 mysql
drwxr-xr-x.  2 root  root    6 5月  18 2020 sbin
drwxr-xr-x.  5 root  root   49 4月  25 19:59 share
drwxr-xr-x.  2 root  root    6 5月  18 2020 src

配置环境变量

[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/loacl/apache/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 6 5月  10 06:05 3306
drwxr-xr-x. 2 mysql mysql 6 5月  10 06:05 3307
drwxr-xr-x. 2 mysql mysql 6 5月  10 06:05 3308

初始化各个实例并保存实例的临时密码

[root@localhost ~]#  mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2021-05-10T10:43:46.637041Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-10T10:43:48.229627Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-10T10:43:48.301554Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-10T10:43:48.368800Z 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: 9a0f4f4c-b17c-11eb-8dac-000c29dd6a28.
2021-05-10T10:43:48.370885Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-10T10:43:48.911191Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-10T10:43:49.220634Z 1 [Note] A temporary password is generated for root@localhost: 7_r<R%>>xc;Y
[root@localhost ~]# echo '7_r<R%>>xc;Y' > 3306_pass
[root@localhost ~]#  mysqld --initialize --datadir=/opt/data/3307 --user=mysql
2021-05-10T10:45:52.929146Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-10T10:45:56.199418Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-10T10:45:56.247973Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-10T10:45:56.311369Z 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: e651cc23-b17c-11eb-bf92-000c29dd6a28.
2021-05-10T10:45:56.312481Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-10T10:45:57.217619Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-10T10:45:58.053859Z 1 [Note] A temporary password is generated for root@localhost: t6JKQkmddg-l
[root@localhost ~]# echo ' t6JKQkmddg-l' > 3307_pass
[root@localhost ~]#  mysqld --initialize --datadir=/opt/data/3308 --user=mysql
2021-05-10T10:48:56.871977Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-10T10:48:57.988832Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-10T10:48:58.061125Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-10T10:48:58.168429Z 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: 52b6fb04-b17d-11eb-9dee-000c29dd6a28.
2021-05-10T10:48:58.441253Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-10T10:49:00.338126Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-10T10:49:01.014721Z 1 [Note] A temporary password is generated for root@localhost: dNV/t#cF;2aO
[root@localhost ~]# echo 'dNV/t#cF;2aO' > 3308_pass

安装perl工具

[root@localhost ~]# dnf install -y perl
上次元数据过期检查:0:17:10 前,执行于 2021年05月10日 星期一 06时34分30秒。
依赖关系解决。
======================================================================
 软件包                       架构   版本             仓库       大小
======================================================================
安装:
 perl                         x86_64 4:5.26.3-419.el8 appstream  73 k
升级:
 perl-Errno                   x86_64 1.28-419.el8     baseos     76 k
 perl-interpreter             x86_64 4:5.26.3-419.el8 baseos    6.3 M
 perl-libs                    x86_64 4:5.26.3-419.el8 baseos    1.6 M
安装依赖关系:
 annobin                      x86_64 9.65-1.el8.0.1   appstream 109 k
 dwz                          x86_64 0.12-9.el8       appstream 109 k
 efi-srpm-macros              noarch 3-3.el8          appstream  22 k
 ghc-srpm-macros              noarch 1.4.2-7.el8      appstream 9.3 k
 go-srpm-macros               noarch 2-17.el8         appstream  13 k
 ocaml-srpm-macros            noarch 5-4.el8          appstream 9.4 k
 openblas-srpm-macros         noarch 2-2.el8          appstream 7.9 k
 perl-Algorithm-Diff          noarch 1.1903-9.el8     baseos     52 k
 perl-Archive-Tar             noarch 2.30-1.el8       baseos     79 k
 perl-Archive-Zip             noarch 1.60-3.el8       appstream 108 k
 perl-Attribute-Handlers      noarch 0.99-419.el8     appstream  89 k
 perl-B-Debug                 noarch 1.26-2.el8       appstream  26 k
 perl-CPAN                    noarch 2.18-397.el8     appstream 554 k
 perl-CPAN-Meta               noarch 2.150010-396.el8 appstream 191 k
 perl-CPAN-Meta-Requirements  noarch 2.140-396.el8    appstream  37 k
 perl-CPAN-Meta-YAML          noarch 0.018-397.el8    appstream  34 k
 perl-Compress-Bzip2          x86_64 2.26-6.el8       appstream  72 k
 perl-Compress-Raw-Bzip2      x86_64 2.081-1.el8      baseos     40 k
 perl-Compress-Raw-Zlib       x86_64 2.081-1.el8      baseos     68 k
 perl-Config-Perl-V           noarch 0.30-1.el8       appstream  22 k

配置配置文件/etc/my.cnf

[root@localhost ~]# vim /etc/my.cnf 
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
Wide character in print at /usr/local/mysql/bin/mysqld_multi line 678.
[root@localhost ~]# mysqld_multi start 3307
Wide character in print at /usr/local/mysql/bin/mysqld_multi line 678.
[root@localhost ~]# mysqld_multi start 3308
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 Process 
LISTEN 0      128            0.0.0.0:111         0.0.0.0:*            
LISTEN 0      128            0.0.0.0:22          0.0.0.0:*            
LISTEN 0      5            127.0.0.1:631         0.0.0.0:*            
LISTEN 0      80                   *:3306              *:*            
LISTEN 0      128               [::]:111            [::]:*            
LISTEN 0      128                  *:80                *:*            
LISTEN 0      128                  *:81                *:*            
LISTEN 0      128               [::]:22             [::]:*            
LISTEN 0      5                [::1]:631            [::]:*  

使用临时密码进入实例并修改密码登录

[root@localhost ~]# mysql -uroot -p'7_r<R%>>xc;Y' -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 2
Server version: 5.7.33

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('huangfangnt');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> quit
Bye
[root@localhost ~]# mysql -uroot -p'huangfangnt' -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.33 MySQL Community Server (GPL)

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> quit
[root@localhost ~]# cat 3307_pass 
 t6JKQkmddg-l
[root@localhost ~]# mysql -uroot -p't6JKQkmddg-l' -S /tmp/mysql3307.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 4
Server version: 5.7.33

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('huangfangnt');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> quit
Bye
[root@localhost ~]# mysql -uroot -p'dNV/t#cF;2aO' -S /tmp/mysql3308.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 2
Server version: 5.7.33

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 ('huangfangnt');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> quit

 

配置开机自启

[root@localhost ~]# cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/
[root@localhost ~]# vim /etc/init.d/mysqld_multi.server 
# This script can be used as /etc/init.d/mysql.server
#
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: A very fast and reliable SQL database engine.
#
# Version 1.0
#

basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
export PATH=/usr/local/mysql/bin:$PATH

if test -x $bindir/mysqld_multi
then
  mysqld_multi="$bindir/mysqld_multi";
else
[root@localhost ~]#  chkconfig mysqld_multi.server on
[root@localhost ~]#  chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

mysqld_multi.server     0:关    1:关    2:开    3:开    4:开    5:开 6:关

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值