千家信息网

MySQL5.6多实例部署

发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,无论是迫于预算,亦或者是领导要求,多实例的安装也是DBA必须掌握的技术,她的启停和登录方式和单实例安装数据库略有不同,本文记录下如何完成MySQL5.6多实例部署。首先我们看一下my.cnf和单实例的
千家信息网最后更新 2026年10月31日MySQL5.6多实例部署

无论是迫于预算,亦或者是领导要求,多实例的安装也是DBA必须掌握的技术,她的启停和登录方式和单实例安装数据库略有不同,本文记录下如何完成MySQL5.6多实例部署。

首先我们看一下my.cnf和单实例的区分:

[root@HE1 scripts]#
cat /etc/my.cnf
[client]
#port = 3306
#socket = /tmp/mysql.sock
#default-character-set = utf8

[mysql]
#default-character-set = utf8

[mysqld3306]
port = 3306
basedir = /usr/local/mysql
datadir = /data/mysql_3306
socket = /tmp/mysql_3306.sock
slow_query_log_file = /data/mysql_3306/slow.log
log-error = /data/mysql_3306/error.log
log-bin = /data/mysql_3306/mysql-bin
sync_binlog = 1
binlog_format = row
transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 100m

[mysqld3308]
port = 3308
basedir = /usr/local/mysql
datadir = /data/mysql_3308
socket = /tmp/mysql_3308.sock
slow_query_log = 1
slow_query_log_file = /data/mysql_3308/slow.log
log-error = /data/mysql_3308/error.log
long_query_time = 1
log-bin = /data/mysql_3308/mysql-bin
sync_binlog = 1
binlog_cache_size = 4M
default-storage-engine = InnoDB
binlog_format = row
transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 100m

[mysqld_multi]
mysqld=/usr/local/mysql/bin/mysqld_safe
mysqladmin=/usr/local/mysql/bin/mysqladmin


[mysqldump]
quick
max_allowed_packet = 32M

可以看出,多实例的my.cnf实际上就是如上所示,本文为了演示实验环境,innodb_buffer_pool_size仅仅开了100m,真实的生产库中多实例部署该参数要开大些,两个实例该参数的值达到内存的50%-80%都可以。

下面开始初始化我们的数据库
首先创建我们的数据目录
[root@HE1 ~]#mkdir -p /data/mysql_3306
[root@HE1 ~]#mkdir -p /data/mysql_3308
[root@HE1 ~]#echo "export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib" >>/etc/profile

进入到mysql的scripts文件夹下对数据库进行初始化,这里我们对3306端口数据库进行初始化
[root@HE1 scripts]#./mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql_3306 --defaults-file=/etc/my.cnf --user=mysql

这里我们对3308端口数据库进行初始化
[root@HE1 scripts]# ./mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql_3308 --defaults-file=/etc/my.cnf --user=mysql

初始化完成后,我们便可以启停数据库了,和单实例不同,多实例采用mysqld_multi来启停数据库
[root@HE1 bin]# ./mysqld_multi --defaults-file=/etc/my.cnf --user=root --password=MANAGER start 3306,3308

可以利用mysqld_multi的report命令来检测多实例的运行状况
1234 [root@HE1 bin]#./mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3306 is running
MySQL server from group: mysqld3308 is running

登录方式和单实例大体相同,不过由于多实例的存在,我们需要指定不同的端口号
[root@HE1 bin]# mysql -uroot -p -P3306 -h 192.168.1.48
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6 Server version: 5.6.16-log MySQL Community Server (GPL)

Copyright (c) 2000,
2014, Oracle and/or its affiliates. All rights reserved.

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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema
|
| 3306db |
| mysql |
| performance_schema
|
| test |
+--------------------+
5 rows in set (0.00 sec)

当然,利用socket文件登录也是可以的
[root@HE1 bin]#mysql -uroot -p -S /data/mysql_3306/mysql_3306.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7 Server version: 5.6.16-log MySQL Community Server (GPL)

Copyright (c) 2000,
2014, Oracle and/or its affiliates. All rights reserved.

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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema
|
| 3306db |
| mysql |
| performance_schema
|
| test |
+--------------------+
5 rows in set (0.00 sec)

这里是登录3308端口数据库
[root@HE1 bin]#mysql -uroot -p -P3308 -h 192.168.1.48
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8 Server version: 5.6.16-log MySQL Community Server (GPL)

Copyright (c) 2000,
2014, Oracle and/or its affiliates. All rights reserved.

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.


Type 'help;' or '\h'
for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema
|
| 3308db |
| mysql |
| performance_schema
|
| test |
+--------------------+
5 rows in set (0.00sec)

mysql> quit
Bye

利用3308端口的socket文件登录数据库
[root@HE1 bin]#mysql -uroot -p -S /data/mysql_3308/mysql_3308.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9 Server version: 5.6.16-log MySQL Community Server (GPL)

Copyright (c) 2000,
2014, Oracle and/or its affiliates. All rights reserved.

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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema
|
| 3308db |
| mysql |
| performance_schema
|
| test |
+--------------------+
5 rows in set (0.00sec)

至此,MySQL5.6多实例部署完成。


实例 数据 数据库 登录 端口 不同 文件 参数 方式 相同 两个 内存 口号 命令 如上 实际 实际上 就是 技术 文件夹 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 手磨咖啡 中智农互联网科技 湖北九亚互联网络科技有限公司 伟宏互联网科技 互联网科技有限公司图片 丰台科技园 互联网 西安互联网科技公司 上海万想互联网科技 互联网高科技企业 互联网科技热点资讯 南平创想时代互联网科技有限公司 昭通互联网科技选哪家 崇明区互联网教育科技售后服务 想开互联网科技公司怎么样 互联网方面的科技前沿 互联网科技股为什么大涨 互联网与数字科技关系 福州德业互联网科技 河南商务圈互联网科技有限公司 科技互联网专业务虚会材料 北京互联网络科技有限公司 农村开互联网科技讲堂 广州恒生互联网科技有限 栖莱科技互联网股份有限公司 成都互联网科技公司工作好不好 卓翼科技产业互联网合作 无锡工业互联网科技有限公司 广西科技产业互联网是什么 求路客互联网科技电话 恒生科技指数 中概互联网
0