MySQL2种多实例部署方式总结
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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:启动方式(独立启动)
[[email protected] ~]# /etc/init.d/mysqldone start [[email protected] ~]# /etc/init.d/mysqltwo start
eg:进程查看|进程查看
[[email protected] ~]# netstat -atupn|grep -E --color ‘3306|3307‘ tcp 0 0 :::3306 :::* LISTEN 7071/mysqld tcp 0 0 :::3307 :::* LISTEN 7077/mysqld [[email protected] ~]#
二、集中部署(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:启动方式:(其它参数可自定义)
[[email protected] ~]# mysqld_multi start 3306,3307 [[email protected] ~]# mysqld_multi report Reporting MySQL servers MySQL server from group: mysqld3306 is running MySQL server from group: mysqld3307 is running [[email protected] ~]# #停止一个实例: [[email protected] ~]# mysqld_multi stop 3306 [[email protected] ~]# mysqld_multi report Reporting MySQL servers MySQL server from group: mysqld3306 is not running MySQL server from group: mysqld3307 is running [[email protected] ~]#
eg:端口查看|进程查看
[[email protected] ~]# netstat -atupn|grep -E --color ‘3306|3307‘ tcp 0 0 :::3306 :::* LISTEN 7071/mysqld tcp 0 0 :::3307 :::* LISTEN 7077/mysqld [[email protected] ~]#
三、客户端访问:
3306:
[[email protected] ~]# 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:
[[email protected] ~]# 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种多实例部署方式总结的主要内容,如果未能解决你的问题,请参考以下文章