当前位置: 首页 > news >正文

多实例部署mysql

多实例部署mysql

1、关闭防火墙和selinux+配置yum网络源+下载mysql压缩包
[root@stw ~]# systemctl stop firewalld.service 
[root@stw ~]# systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@stw ~]# setenforce 0
[root@stw ~]# vim /etc/selinux/config 
[root@stw ~]# getenforce 
Permissive
[root@stw ~]# reboot
[root@stw ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg                        Public
Desktop          Music                                       Templates
Documents        mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz  Videos
Downloads        Pictures
[root@stw ~]# cd /etc/yum.repos.d/
[root@stw yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@stw yum.repos.d]# rm -rf *
[root@stw yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100  2523  100  2523    0     0   7316      0 --:--:-- --:--:-- --:--:--  7334
[root@stw yum.repos.d]# ls
CentOS-Base.repo
[root@stw yum.repos.d]# yum -y install epel-release
[root@stw yum.repos.d]# ls
CentOS-Base.repo  epel.repo  epel-testing.repo
2、安装 libncurses* 依赖包(可省略)
[root@stw ~]# yum -y install libncurses*
Package ncurses-libs-5.9-14.20130511.el7_4.x86_64 already installed and latest version
Nothing to do   //这里显示已经安装
3、创建用户和组
[root@stw ~]# groupadd -r mysql
[root@stw ~]# useradd -M -s /sbin/nologin -g mysql mysql
[root@stw ~]# id mysql
uid=1001(mysql) gid=982(mysql) groups=982(mysql)
4、解压软件至/usr/local/并创建软链接
[root@stw ~]# tar -zxvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local mysql
[root@stw ~]# cd /usr/local/
[root@stw local]# ls
bin  games    lib    libexec                              sbin   src
etc  include  lib64  mysql-5.7.37-linux-glibc2.12-x86_64  share
[root@stw local]# ln -s mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
[root@stw local]# ll
total 0
drwxr-xr-x. 2 root root   6 Apr 11  2018 bin
drwxr-xr-x. 2 root root   6 Apr 11  2018 etc
drwxr-xr-x. 2 root root   6 Apr 11  2018 games
drwxr-xr-x. 2 root root   6 Apr 11  2018 include
drwxr-xr-x. 2 root root   6 Apr 11  2018 lib
drwxr-xr-x. 2 root root   6 Apr 11  2018 lib64
drwxr-xr-x. 2 root root   6 Apr 11  2018 libexec
lrwxrwxrwx  1 root root  36 Sep 19 11:01 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x  9 root root 129 Sep 19 11:00 mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 Apr 11  2018 sbin
drwxr-xr-x. 5 root root  49 Jul 23 11:56 share
drwxr-xr-x. 2 root root   6 Apr 11  2018 src
5、修改目录/usr/local/mysql的属主属组
[root@stw mysql]# chown -R mysql.mysql /usr/local/mysql/
[root@stw local]# ll -d /usr/local/mysql
lrwxrwxrwx 1 mysql mysql 36 Sep 19 11:01 /usr/local/mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
[root@stw local]# cd mysql
[root@stw mysql]# ll
total 272
drwxr-xr-x  2 mysql mysql   4096 Sep 19 11:00 bin
drwxr-xr-x  2 mysql mysql     55 Sep 19 11:00 docs
drwxr-xr-x  3 mysql mysql   4096 Sep 19 11:00 include
drwxr-xr-x  5 mysql mysql    230 Sep 19 11:00 lib
-rw-r--r--  1 mysql mysql 259253 Nov 30  2021 LICENSE
drwxr-xr-x  4 mysql mysql     30 Sep 19 11:00 man
-rw-r--r--  1 mysql mysql    566 Nov 30  2021 README
drwxr-xr-x 28 mysql mysql   4096 Sep 19 11:00 share
drwxr-xr-x  2 mysql mysql     90 Sep 19 11:00 support-files
6、配置环境变量
[root@stw ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@stw ~]# cat /etc/profile.d/mysql.sh 
export PATH=/usr/local/mysql/bin:$PATH
[root@stw ~]# . /etc/profile.d/mysql.sh    //运行此脚本
7、创建各实例数据存放的目录并将其所有者和所属组都改为mysql组
[root@stw ~]# mkdir -p /opt/data/{3306..3308}
[root@stw ~]# ls /opt/data
3306  3307  3308
[root@stw ~]# chown -R mysql.mysql /opt/data/
[root@stw ~]# ll -d /opt/data
drwxr-xr-x 5 mysql mysql 42 Sep 19 11:15 /opt/data
[root@stw ~]# cd /opt/data
[root@stw data]# ll
total 0
drwxr-xr-x 2 mysql mysql 6 Sep 19 11:15 3306
drwxr-xr-x 2 mysql mysql 6 Sep 19 11:15 3307
drwxr-xr-x 2 mysql mysql 6 Sep 19 11:15 3308
8、初始化3306实例(并将生成的密码重定向到3306文件中)
[root@stw ~]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2025-09-19T03:19:53.313330Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2025-09-19T03:19:53.734715Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-09-19T03:19:53.802030Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-09-19T03:19:53.904191Z 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: 82ba4984-9507-11f0-a284-000c29b9a32a.
2025-09-19T03:19:53.905685Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-09-19T03:19:55.877239Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:19:55.877261Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:19:55.880916Z 0 [Warning] CA certificate ca.pem is self signed.
2025-09-19T03:19:56.492273Z 1 [Note] A temporary password is generated for root@localhost: shKBQpf:I7Ug
[root@stw ~]# echo 'shKBQpf:I7Ug' > 3306
[root@stw ~]# cat 3306
shKBQpf:I7Ug
9、初始化3307实例(并将生成的密码重定向到3307文件中)
[root@stw ~]# mysqld --initialize --datadir=/opt/data/3307 --user=mysql
2025-09-19T03:22:14.389157Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2025-09-19T03:22:14.953903Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-09-19T03:22:15.074010Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-09-19T03:22:15.176918Z 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: d6eecbce-9507-11f0-a725-000c29b9a32a.
2025-09-19T03:22:15.178270Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-09-19T03:22:16.094502Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:22:16.094525Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:22:16.095841Z 0 [Warning] CA certificate ca.pem is self signed.
2025-09-19T03:22:16.843750Z 1 [Note] A temporary password is generated for root@localhost: yMk&Jas5!AD0
[root@stw ~]# echo 'yMk&Jas5!AD0' > 3307
[root@stw ~]# cat 3307
yMk&Jas5!AD0
10、初始化3308实例(并将生成的密码重定向到3308文件中)
[root@stw ~]# mysqld --initialize --datadir=/opt/data/3308 --user=mysql
2025-09-19T03:22:50.600213Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2025-09-19T03:22:51.120379Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-09-19T03:22:51.204391Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-09-19T03:22:51.287530Z 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: ec74d6bd-9507-11f0-aa7d-000c29b9a32a.
2025-09-19T03:22:51.289424Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-09-19T03:22:52.438302Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:22:52.438335Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:22:52.445813Z 0 [Warning] CA certificate ca.pem is self signed.
2025-09-19T03:22:52.813578Z 1 [Note] A temporary password is generated for root@localhost: 1Rvd&58hkzrj
[root@stw ~]# echo '1Rvd&58hkzrj' > 3308
[root@stw ~]# cat 3308
1Rvd&58hkzrj
11、安装perl
[root@stw ~]# yum -y install perl
12、更改配置文件/etc/my.cnf,并起服务
[root@stw ~]# vim /etc/my.cnf
[root@stw ~]# 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@stw ~]# mysqld_multi start 3306
[root@stw ~]# mysqld_multi start 3307
[root@stw ~]# mysqld_multi start 3308
[root@stw ~]# ss -anlt
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128          *:111                      *:*                  
LISTEN     0      128          *:6000                     *:*                  
LISTEN     0      5      192.168.122.1:53                       *:*                  
LISTEN     0      128          *:22                       *:*                  
LISTEN     0      128    127.0.0.1:631                      *:*                  
LISTEN     0      100    127.0.0.1:25                       *:*                  
LISTEN     0      128    127.0.0.1:6010                     *:*                  
LISTEN     0      80          :::3306                    :::*                  
LISTEN     0      80          :::3307                    :::*                  
LISTEN     0      80          :::3308                    :::*                  
LISTEN     0      128         :::111                     :::*                  
LISTEN     0      128         :::6000                    :::*                  
LISTEN     0      128         :::22                      :::*                  
LISTEN     0      128        ::1:631                     :::*                  
LISTEN     0      100        ::1:25                      :::*                  
LISTEN     0      128        ::1:6010                    :::*       
13、登录数据库并更改密码
3306:
[root@stw ~]# cat 3306
shKBQpf:I7Ug
[root@stw ~]# mysql -uroot -p'shKBQpf:I7Ug' -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.37Copyright (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('redhat');
Query OK, 0 rows affected, 1 warning (0.01 sec)mysql> exit
Bye
[root@stw ~]# mysql -uroot -p'redhat' -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.37 MySQL Community Server (GPL)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> flush privileges;
Query OK, 0 rows affected (0.01 sec)
3307:
[root@stw ~]# mysql -uroot -p'yMk&Jas5!AD0' -S /tmp/mysql3307.sock -e 'set password = password("redhat");' --connect-expired-password
//--connect-expired-password  连接失效的密码
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@stw ~]# mysql -uroot -predhat -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 3
Server version: 5.7.37 MySQL Community Server (GPL)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> flush privileges;
Query OK, 0 rows affected (0.01 sec)
3308:
[root@stw ~]# cat 3308
1Rvd&58hkzrj
[root@stw ~]# mysql -uroot -p'1Rvd&58hkzrj' -S /tmp/mysql3308.sock -e 'set password = password("redhat");' --connect-expired-password
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@stw ~]# mysql -uroot -predhat -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 3
Server version: 5.7.37 MySQL Community Server (GPL)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> flush privileges;
Query OK, 0 rows affected (0.01 sec)
注意:更改完密码后最后用 flush privileges; 刷新一下权限
http://www.dtcms.com/a/391831.html

相关文章:

  • 信创国产化改造(改成人大金仓)
  • 远程修改的烦恼FacePoke和cpolar联手已帮您解决
  • 基于MCP的README生成协议
  • (1)什么是机器学习?
  • 【数据结构——邻接表】
  • RNA-seq分析之单基因Wilcoxon秩和检验
  • 四网络层IP-子网掩码ARP CIDR RIP OSPF BGP 路由算法-思考题
  • [重学Rust]之智能指针
  • 团体程序设计天梯赛-练习集 L1-036 A乘以B
  • H2数据库(tcp 服务器模式)调优
  • C# 面试记录
  • 深度学习(十):逻辑回归的代价函数
  • FreeRTOS学习笔记(六):汇编指令笔记
  • 【复刻】中国城市数字经济发展对环境污染的影响及机理研究(2011-2021年)
  • Blazer:一个免费开源、基于SQL的数据分析与可视化工具
  • 软件体系架构——系统架构评估与ATAM
  • sam2 docker部署
  • 深度学习------卷积神经网络
  • Amazon SES + NestJS 实战:零成本打造高送达率邮箱验证方案
  • MySQL 8.0临时表空间深度解析
  • 低秩矩阵:揭示高维数据中的简约之美
  • QR Wizard for Mac 好用的二维码生成器
  • 【redis】redis知识点
  • C语言模版(机试666)
  • 高通camx架构学习(二)——深入理解高通Camx Hal
  • 戴尔笔记本的奇怪功能
  • Linux文件系统结构与用户管理完全指南
  • 鸿蒙保存图片到相册
  • 【C语言】喝汽水问题分析:20元能喝多少瓶汽水?
  • 二物理层-ADSL-思考题