mysql多实例部署

mysql多实例部署

软件下载

[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-31 15:08:46--  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)... 104.89.9.126, 2600:1405:1800:184::2e31, 2600:1405:1800:19c::2e31
Connecting to downloads.mysql.com (downloads.mysql.com)|104.89.9.126|: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-31 15:08:48--  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.203.29.47
Connecting to cdn.mysql.com (cdn.mysql.com)|23.203.29.47|: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-li 100%[=======>] 643.57M  1.86MB/s    in 9m 52s  

2022-07-31 15:18:41 (1.09 MB/s) - 'mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz' saved [674830866/674830866]

配置用户和组并解压二进制程序至/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.38-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# tar xf  mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# ls
debug  kernels  mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# cd
[root@localhost ~]# ls
anaconda-ks.cfg
[root@localhost ~]# ls /usr/local/
bin    include  libexec                              share
etc    lib      mysql-5.7.38-linux-glibc2.12-x86_64  src
games  lib64    sbin
[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 May 19  2020 bin
drwxr-xr-x. 2 root root   6 May 19  2020 etc
drwxr-xr-x. 2 root root   6 May 19  2020 games
drwxr-xr-x. 2 root root   6 May 19  2020 include
drwxr-xr-x. 2 root root   6 May 19  2020 lib
drwxr-xr-x. 3 root root  17 Jun 27 19:38 lib64
drwxr-xr-x. 2 root root   6 May 19  2020 libexec
lrwxrwxrwx. 1 root root  36 Jul 31 15:23 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 Jul 31 15:21 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 May 19  2020 sbin
drwxr-xr-x. 5 root root  49 Jun 27 19:38 share
drwxr-xr-x. 2 root root   6 May 19  2020 src

//修改目录/usr/local/mysql的属主属组
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
[root@localhost ~]# ll -d  /usr/local/mysql 
lrwxrwxrwx. 1 mysql mysql 36 Jul 31 15:23 /usr/local/mysql -> mysql-5.7.38-linux-glibc2.12-x86_64/

//配置环境变量
[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 ~]# 
[root@localhost ~]# ll /opt/data/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jul 31 15:25 3306
drwxr-xr-x. 2 mysql mysql 6 Jul 31 15:25 3307
drwxr-xr-x. 2 mysql mysql 6 Jul 31 15:25 3308

[root@localhost ~]# tree /opt/data/
/opt/data/
|-- 3306
|-- 3307
`-- 3308

3 directories, 0 files    

初始化各实例

//初始化3306实例
[root@localhost ~]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2022-07-31T07:27:22.844048Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-31T07:27:22.967550Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-31T07:27:22.988498Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-31T07:27:23.043721Z 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: 381bab10-10a2-11ed-823b-000c296afe0a.
2022-07-31T07:27:23.044355Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-31T07:27:23.287901Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-31T07:27:23.287910Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-31T07:27:23.288216Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-31T07:27:23.340381Z 1 [Note] A temporary password is generated for root@localhost: o7kHMpi4Df)q
[root@localhost ~]# echo 'o7kHMpi4Df)q' > 3306_pass
[root@localhost ~]# ls
3306_pass  anaconda-ks.cfg
[root@localhost ~]# cat 3306_pass 
o7kHMpi4Df)q

//初始化3307实例
[root@localhost ~]# mysqld --initialize --datadir=/opt/data/3307 --user=mysql
2022-07-31T07:29:16.704361Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-31T07:29:16.818612Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-31T07:29:16.846711Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-31T07:29:16.901854Z 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: 7bf90a75-10a2-11ed-9716-000c296afe0a.
2022-07-31T07:29:16.902509Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-31T07:29:17.059790Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-31T07:29:17.059801Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-31T07:29:17.060093Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-31T07:29:17.209983Z 1 [Note] A temporary password is generated for root@localhost: Xy/lfLU#j2f_
[root@localhost ~]# echo 'Xy/lfLU#j2f_' > 3307_pass
[root@localhost ~]# ls
3306_pass  3307_pass  anaconda-ks.cfg
[root@localhost ~]# cat 3307_pass 
Xy/lfLU#j2f_
      
//初始化3308实例
[root@localhost ~]# mysqld --initialize --datadir=/opt/data/3308 --user=mysql
2022-07-31T07:30:55.317345Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-31T07:30:55.429328Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-31T07:30:55.447016Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-31T07:30:55.502501Z 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: b6be4e3a-10a2-11ed-996f-000c296afe0a.
2022-07-31T07:30:55.502960Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-31T07:30:55.773249Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-31T07:30:55.773261Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-31T07:30:55.773699Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-31T07:30:55.785725Z 1 [Note] A temporary password is generated for root@localhost: -C1C:uDrXpT-
[root@localhost ~]# echo '-C1C:uDrXpT-' > 3308_pass
[root@localhost ~]# ls
3306_pass  3307_pass  3308_pass  anaconda-ks.cfg
[root@localhost ~]# cat 3308_pass 
-C1C:uDrXpT-  

配置配置文件/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

启动各实例

需要安装perl

//安装perl
[root@localhost ~]# mysqld_multi start 3306
-bash: /usr/local/mysql/bin/mysqld_multi: /usr/bin/perl: bad interpreter: No such file or directory
[root@localhost ~]# dnf -y install perl
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:15:48 ago on Sun Jul 31 15:20:03 2022.
Dependencies resolved.
================================================================
 Package                Arch   Version          Repo       Size
================================================================
Installing:
 perl                   x86_64 4:5.26.3-421.el8 appstream  73 k
Installing dependencies:
................................
    
//启动各实例    
[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:PortProcess
LISTEN 0      128          0.0.0.0:22        0.0.0.0:*          
LISTEN 0      80                 *:3306            *:*          
LISTEN 0      80                 *:3307            *:*          
LISTEN 0      80                 *:3308            *:*          
LISTEN 0      128             [::]:22           [::]:*     

初始化密码

//登录实例修改密码
[root@localhost ~]# mysql -uroot -p'o7kHMpi4Df)q' -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.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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye


[root@localhost ~]# ls
3306_pass  3307_pass  3308_pass  anaconda-ks.cfg
[root@localhost ~]# cat 3307_pass 
Xy/lfLU#j2f_
[root@localhost ~]# mysql -uroot -p'Xy/lfLU#j2f_' -S /tmp/mysql3307.sock -e 'set password = password("123456");' --connect-expired-password
mysql: [Warning] Using a password on the command line interface can be insecure.


[root@localhost ~]# ls
3306_pass  3307_pass  3308_pass  anaconda-ks.cfg
[root@localhost ~]# cat 3308_pass 
-C1C:uDrXpT-
[root@localhost ~]# mysql -uroot -p'-C1C:uDrXpT-' -S /tmp/mysql3308.sock -e 'set password = password("123456");' --connect-expired-password
mysql: [Warning] Using a password on the command line interface can be insecure.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要停止MySQL的多实例,可以使用以下命令: ``` mysqld_multi --user=root --password=123456 stop 实例号 ``` 其中,`实例号`是指要停止的具体实例的编号。 如果你不知道实例的编号,可以使用以下命令查看正在运行的MySQL实例: ``` ss -nultp | grep 3306 ``` 上述命令将显示所有监听在端口3306的MySQL连接。你可以根据输出确定要停止的实例的编号。 请注意,在以上命令中,`--user=root --password=123456`是选项,用于指定MySQL实例的用户和密码。你需要根据你的实际情况将其替换为你自己的用户名和密码。 希望以上信息对你有帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [MySQL实例部署](https://blog.csdn.net/m0_58805648/article/details/125574677)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [MySQL实例的配置](https://blog.csdn.net/hahaxixi131/article/details/122137583)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值