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

49.Mysql多实例部署

Mysql多实例部署

配置网络yum源

[root@xieyuhui yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@xieyuhui yum.repos.d]# yum install epel-release -y

将软件包解压至/usr/local

[root@xieyuhui ~]# tar -xzvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

创建mysql的用户和组

[root@xieyuhui ~]# useradd -M -s /sbin/nologin -g mysql mysql

创建软连接

[root@xieyuhui ~]# ln -s mysql-5.7.37-linux-glibc2.12-x86_64/ mysql

修改/usr/local/mysql的所有者和所属组

[root@xieyuhui local]# chown -R mysql.mysql /usr/local/

给mysql配置环境变量

[root@xieyuhui ~]# cd /etc/profile.d/
[root@xieyuhui profile.d]# vim mysql.shexport PATH=/usr/local/mysql/bin:$PATH
[root@xieyuhui profile.d]# . /etc/profile.d/mysql.sh

创建mysql存放数据的目录

[root@xieyuhui profile.d]# mkdir -p /opt/data/{3306..3308}
把所有者和所属组换成mysql
[root@xieyuhui ~]# chown -R mysql.mysql /opt/data/

初始化各实例

初始化3306
[root@xieyuhui ~]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2025-09-19T03:14:36.425495Z 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:14:36.563218Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-09-19T03:14:36.586074Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-09-19T03:14:36.641190Z 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: c59fcbf4-9506-11f0-a261-000c299a729a.
2025-09-19T03:14:36.641778Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-09-19T03:14:37.267042Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:14:37.267057Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:14:37.268002Z 0 [Warning] CA certificate ca.pem is self signed.
2025-09-19T03:14:37.646367Z 1 [Note] A temporary password is generated for root@localhost: W==<fgaes8_4  #密码为 W==<fgaes8_4
初始化3307
[root@xieyuhui ~]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2025-09-19T03:14:36.425495Z 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:14:36.563218Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-09-19T03:14:36.586074Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-09-19T03:14:36.641190Z 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: c59fcbf4-9506-11f0-a261-000c299a729a.
2025-09-19T03:14:36.641778Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-09-19T03:14:37.267042Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:14:37.267057Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:14:37.268002Z 0 [Warning] CA certificate ca.pem is self signed.
2025-09-19T03:14:37.646367Z 1 [Note] A temporary password is generated for root@localhost: W==<fgaes8_4
[root@xieyuhui ~]# mysqld --initialize --datadir=/opt/data/3307 --user=mysql
2025-09-19T03:16:03.598504Z 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:16:03.755562Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-09-19T03:16:03.779952Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-09-19T03:16:03.835328Z 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: f9989142-9506-11f0-a6b2-000c299a729a.
2025-09-19T03:16:03.836259Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-09-19T03:16:04.050270Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:16:04.050286Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:16:04.050859Z 0 [Warning] CA certificate ca.pem is self signed.
2025-09-19T03:16:04.234285Z 1 [Note] A temporary password is generated for root@localhost: kziwiirws5%R 	#密码为 kziwiirws5%R
初始化3308
[root@xieyuhui ~]# mysqld --initialize --datadir=/opt/data/3308 --user=mysql
2025-09-19T03:16:44.060313Z 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:16:44.241776Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-09-19T03:16:44.276190Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-09-19T03:16:44.331489Z 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: 11bbca1b-9507-11f0-a891-000c299a729a.
2025-09-19T03:16:44.332395Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-09-19T03:16:44.802039Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:16:44.802055Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:16:44.802510Z 0 [Warning] CA certificate ca.pem is self signed.
2025-09-19T03:16:44.962209Z 1 [Note] A temporary password is generated for root@localhost: N#aw<G?si9rZ 	#密码为 N#aw<G?si9rZ

安装perl

[root@xieyuhui ~]# yum -y install perl

编辑多实例配置文件

[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@xieyuhui ~]# mysqld_multi start 3306
[root@xieyuhui ~]# mysqld_multi start 3307
[root@xieyuhui ~]# mysqld_multi start 3308

初始化密码

[root@xieyuhui ~]# mysql -uroot -p'W==<fgaes8_4' -S /tmp/mysql3306.sock -e 'set password = password("redhat");' --connect-expired-password
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@xieyuhui ~]# mysql -uroot -p'kziwiirws5%R' -S /tmp/mysql3307.sock -e 'set password = password("redhat");' --connect-expired-password
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@xieyuhui ~]# mysql -uroot -p'N#aw<G?si9rZ' -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.

登录mysql查看

[root@xieyuhui ~]# mysql -uroot -predhat -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>
[root@xieyuhui ~]# 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.
[root@xieyuhui ~]# 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>
http://www.dtcms.com/a/391317.html

相关文章:

  • java 上传文件和下载/预览文件 包括音频调进度条
  • 部署你的 Next.js 应用:Vercel、Netlify 和自托管选项
  • 从产品经理视角:小智AI的产品介绍与分析
  • 解决:导包红色波浪线但正常运行及其后续问题
  • webrtc弱网-LinkCapacityEstimator类源码分析与算法原理
  • vue el-autocomplete输入框自动匹配优化,建议项按高度相似降序
  • 十分钟了解@Version注解
  • vue3+ts+uniapp H5微信小程序app有截止日期的日期date-pcicker组件
  • 设计模式-观察者模式详解
  • centos7--安装海量数据库Vastbase M100
  • Apache Commons DBCP连接池生产环境配置推荐
  • 【11/20】实时数据基础:WebSocket 在 Express 和 Vue 中的整合,实现简单聊天功能
  • 五传输层-TCP UDP慢启动-真题
  • ARM基础知识
  • 从零开始的指针(5)
  • TDMQ CKafka 版客户端实战指南系列之二:消费消息最佳实践
  • Comcast 没有对比就没有伤害
  • AI悬浮窗 1.0 | 快捷提取文字,总结信息,支持提取文字、理解屏幕上的图案、总结分析信息
  • MySQL、PostgreSQL、MongoDB和Redis全面对比
  • 隐私保护与数据安全合规(七)
  • 登录 双层拦截器+redis
  • TM56M152A (SOP16) HITENX海速芯 8位微控制器MCU 芯片深度解析
  • 理解元学习器 - 如何使用机器学习估计异质处理效应(四)
  • [数据结构] Map和Set
  • [Go类库分享]Go template模版库
  • 辅助搜题系统-基于模糊搜索,上传word题库后,可搜索答案
  • 【完整源码+数据集+部署教程】遥感农田森林岩石图像分割系统: yolov8-seg-C2f-DCNV2
  • RTX 4090助力深度学习:从PyTorch到生产环境的完整实践指南
  • AWS中国云中的调用链监控(EC2版)
  • CI/CD到底是什么?