首页 > 代码库 > MySQL2种多实例部署方式总结
MySQL2种多实例部署方式总结
多实例在生产很常用,一方面节约了成本,一方面可以充分利用资源,提高数据处理速度(服务器性能够好),之前请教过贺磊dba一点MySQL多实例一些问题,部署安装比较简单,这里总结一下MySQL多实例部署的两种方式:
注意事项 | 单独管理 | 集中管理(mysqld_multi) |
配置文件 | 使用不同的配置文件 | 共用一个配置文件 |
端口 | 不可冲突 | 不可冲突 |
basedir | 可单独目录/可相同目录 | 可单独目录/可相同目录 |
datadir | 不相同 | 不相同 |
pid文件 | 不可冲突/独立访问 | 不可冲突/独立访问 |
sock | 不可冲突/独立访问 | 不可冲突/独立访问 |
log | 不可冲突/独立访问 | 不可冲突/独立访问 |
启动方式 | 自定义、分别文件管理启动 | mysqld_multi集中管理 |
优点缺点 | 步骤稍微多一些,独自管理,风险略小 | 步骤简单,需要一定技术含量管理维护 |
eg配置文件:(单独管理)
#MySQLone /usr/local/mysqlone/my.cnf #MySQLtwo /usr/local/mysqltwo/my.cnf
eg:启动方式(独立启动)
[root@MySQL ~]# /etc/init.d/mysqldone start [root@MySQL ~]# /etc/init.d/mysqltwo start
eg:进程查看|进程查看
[root@MySQL ~]# netstat -atupn|grep -E --color ‘3306|3307‘ tcp 0 0 :::3306 :::* LISTEN 7071/mysqld tcp 0 0 :::3307 :::* LISTEN 7077/mysqld [root@MySQL ~]#
二、集中部署(mysqld_multi)
eg:配置文件(集中管理)
/etc/my.cnf [mysqld3306] port = 3306 basedir = /usr/local/mysql datadir = /usr/local/mysql/data/mysqlone #启动可自定义,也可配置文件定义 #socket = #pidfile = log-error [mysqld3308] port = 3307 basedir = /usr/local/mysql datadir = /usr/local/mysql/data/mysqltwo #启动可自定义,也可配置文件定义 #socket = #pidfile = #log-error [mysqld_multi] mysqld=/usr/local/mysql/bin/mysqld_safe mysqladmin=/usr/local/mysql/bin/mysqladmin
eg:初始化方式:
/usr/local/mysql/scripts/mysql_install_db --datadir=/usr/local/mysql/data/MySQL_3306 --basedir=/usr/local/mysql --user=mysql /usr/local/mysql/scripts/mysql_install_db --datadir=/usr/local/mysql/data/MySQL_3307 --basedir=/usr/local/mysql --user=mysql
eg:启动方式:(其它参数可自定义)
[root@MySQL ~]# mysqld_multi start 3306,3307 [root@MySQL ~]# mysqld_multi report Reporting MySQL servers MySQL server from group: mysqld3306 is running MySQL server from group: mysqld3307 is running [root@MySQL ~]# #停止一个实例: [root@MySQL ~]# mysqld_multi stop 3306 [root@MySQL ~]# mysqld_multi report Reporting MySQL servers MySQL server from group: mysqld3306 is not running MySQL server from group: mysqld3307 is running [root@MySQL ~]#
eg:端口查看|进程查看
[root@MySQL ~]# netstat -atupn|grep -E --color ‘3306|3307‘ tcp 0 0 :::3306 :::* LISTEN 7071/mysqld tcp 0 0 :::3307 :::* LISTEN 7077/mysqld [root@MySQL ~]#
三、客户端访问:
3306:
[root@MySQL ~]# mysql --sock=/usr/local/mysql/data/MySQL_3306/mysql.sock Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.21-log MySQL Community Server (GPL) Copyright (c) 2000, 2013, 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>
3307:
[root@MySQL ~]# mysql --sock=/usr/local/mysql/data/MySQL_3307/mysql.sock Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.6.21-log MySQL Community Server (GPL) Copyright (c) 2000, 2013, 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>
如有不足,可指教。
本文出自 “永不放弃!任志远” 博客,谢绝转载!
MySQL2种多实例部署方式总结
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。