mysql多实例部署
文章目录
文章目录
软件下载
[root@linux-1 ~]# cd /usr/src/
[root@linux-1 src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
--2022-07-26 21:01:57-- https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
Resolving downloads.mysql.com (downloads.mysql.com)... 96.7.99.160, 2600:140e:6:9bc::2e31, 2600:140e:6:9a3::2e31
Connecting to downloads.mysql.com (downloads.mysql.com)|96.7.99.160|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz [following]
--2022-07-26 21:01:58-- 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.194.211.12
Connecting to cdn.mysql.com (cdn.mysql.com)|23.194.211.12|: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 100%[==============>] 643.57M 9.39MB/s in 68s
2022-07-26 21:03:07 (9.49 MB/s) - 'mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz' saved [674830866/674830866]
[root@linux-1 src]# ls
debug kernels mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@linux-1 src]#
配置用户和组并解压二进制程序至/usr/local下
[root@localhost src]# groupadd -r mysql //创建组
[root@localhost src]# useradd -M -s /sbin/nologin -g mysql mysql //把用户mysql加入组
[root@localhost src]# ls
[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 ~]# cd /usr/local/
[root@localhost local]# ls
bin games lib libexec sbin src
etc include lib64 mysql-5.7.38-linux-glibc2.12-x86_64 share
[root@localhost local]# ln -sv mysql-5.7.38-linux-glibc2.12-x86_64/ mysql //创建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 28 04:58 lib64
drwxr-xr-x. 2 root root 6 Jun 22 2021 libexec
lrwxrwxrwx. 1 root root 36 Jul 31 20:19 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 Jul 31 20:18 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 28 04:58 share
drwxr-xr-x. 2 root root 6 Jun 22 2021 src
修改目录的属组属主,后做环境变量。
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
[root@localhost ~]# ll /usr/local/
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 28 04:58 lib64
drwxr-xr-x. 2 root root 6 Jun 22 2021 libexec
lrwxrwxrwx. 1 mysql mysql 36 Jul 31 20:19 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 Jul 31 20:18 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 28 04:58 share
drwxr-xr-x. 2 root root 6 Jun 22 2021 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/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/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jul 31 20:24 3306
drwxr-xr-x. 2 mysql mysql 6 Jul 31 20:24 3307
[root@localhost ~]# tree /opt/data/
/opt/data/
|-- 3306
|-- 3307
`-- 3308
3 directories, 0 files
初始化各实例
[root@localhost ~]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2022-08-01T00:25:44.884754Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-08-01T00:25:45.054600Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-01T00:25:45.078791Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-08-01T00:25:45.083722Z 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: 7bc3108c-1130-11ed-8302-000c2984ee47.
2022-08-01T00:25:45.085571Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-08-01T00:25:45.374956Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-08-01T00:25:45.374993Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-01T00:25:45.375300Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-01T00:25:45.422852Z 1 [Note] A temporary password is generated for root@localhost: mpFwdr8pVS>S
[root@localhost ~]# mysqld --initialize --datadir=/opt/data/3307 --user=mysql
2022-08-01T00:32:27.325217Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-08-01T00:32:27.498353Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-01T00:32:27.521646Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-08-01T00:32:27.537948Z 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: 6ba4b4c6-1131-11ed-8c66-000c2984ee47.
2022-08-01T00:32:27.538688Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-08-01T00:32:27.857723Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-08-01T00:32:27.857759Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-01T00:32:27.858202Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-01T00:32:27.893663Z 1 [Note] A temporary password is generated for root@localhost: lcRfPWREl4(r
[root@localhost ~]# mysqld --initialize --datadir=/opt/data/3308 --user=mysql
2022-08-01T00:32:36.905254Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-08-01T00:32:37.077902Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-08-01T00:32:37.107208Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-08-01T00:32:37.112477Z 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: 7159a9e4-1131-11ed-a78b-000c2984ee47.
2022-08-01T00:32:37.115009Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-08-01T00:32:37.228711Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-08-01T00:32:37.228741Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-08-01T00:32:37.229121Z 0 [Warning] CA certificate ca.pem is self signed.
2022-08-01T00:32:37.368927Z 1 [Note] A temporary password is generated for root@localhost: 7wPvzuu9gw;1
安装珍珠
[root@localhost ~]# yum -y install perl
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:18:36 ago on Sun Jul 31 20:14:12 2022.
Dependencies resolved.
==========================================================================
Package Arch Version Repo Size
==========================================================================
Installing:
perl x86_64 4:5.26.3-421.el8 appstream 73 k
Installing dependencies:
dwz x86_64 0.12-10.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
...
python3-rpm-macros-3-42.el8.noarch
qt5-srpm-macros-5.15.3-1.el8.noarch
redhat-rpm-config-130-1.el8.noarch
rust-srpm-macros-5-2.el8.noarch
systemtap-sdt-devel-4.7-1.el8.x86_64
unzip-6.0-46.el8.x86_64
zip-3.0-23.el8.x86_64
Complete!
[root@localhost ~]#
配置配置文件/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
启动各个实例
[root@localhost ~]# mysqld_multi start 3306
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "zh_CN.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
[root@localhost ~]# ss -antl
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 [::]:*
LISTEN 0 80 *:3306 *:*
[root@localhost ~]# mysqld_multi start 3307
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "zh_CN.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
[root@localhost ~]# mysqld_multi start 3308
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "zh_CN.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
[root@localhost ~]# ss -antl
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 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 80 *:3307 *:*
LISTEN 0 80 *:3308 *:*
[root@localhost ~]#
启动mysql各个数据库
[root@localhost ~]# mysql -uroot -p -S /tmp/mysql3307.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.38
Copyright (c) 2000, 2022, 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('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
[root@localhost ~]# mysql -uroot -p -S /tmp/mysql3306.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.38
Copyright (c) 2000, 2022, 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('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
[root@localhost ~]# mysql -uroot -p -S /tmp/mysql3308.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.38
Copyright (c) 2000, 2022, 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('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit
注;如果有启动报出没有这个目录的错误输入一下命令解决
yum install ncurses-compat-libs