可以管理多个帧听不同Unix套接字文件和TCP/IP端口的连接的mysqld 进程。它可以启动或停止服务器,或报告它们的当前状态。
即可以管理多个实例。
之前使用mysql_safe启用多实例的方法,启动和关闭都指定配置文件,实例间是对立的,互不影响。成功的部署了多个实例主从Replication
mysql_multi多实例管理,配置简单,方便管理。
说明
实战
1.配置my.cnf文件
~]# cat /etc/my.cnf
[mysqld_multi]
mysqld = /usr/bin/mysqld_safe #根据自己的mysql目录配置,使用which command可以查询路径
mysqladmin = /usr/bin/mysqladmin
[mysqld] #之前已经正常使用的mysql实例
basedir=/usr
datadir = /data/mysql
port = 3306
server_id = 2
socket = /tmp/mysql3306.sock
skip-host-cache
skip-name-resolve
character-set-server=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket=/tmp/mysql3306.sock #配置client默认使用的scoket文件
#mysqld1和mysqld2是使用mysqld_multi启动的多个实例
[mysqld1]
basedir=/usr
datadir = /data/mysql1
port = 3307
server_id = 3
socket = /tmp/mysql3307.sock
skip-host-cache
skip-name-resolve
character-set-server=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld2]
basedir=/usr
datadir = /data/mysql2
port = 3308
server_id = 3
socket = /tmp/mysql3308.sock
skip-host-cache
skip-name-resolve
character-set-server=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
注:配置文件中其他的参数跟正常的mysqld下一样 根据实际需要设置即可
2.拷贝mysqld的文件到mysqld1和mysqld2对应的datadir
~]# cp -pr /data/mysql /data/mysql1
~]# cp -pr /data/mysql /data/mysql2
3.启动mysqld1和mysqld2实例--使用mysqld_multi
~]# mysqld_multi start 1
~]# mysqld_multi start 2
Usage: mysqld_multi [OPTIONS] {start|reload|stop|report} [GNR,GNR,GNR...]
or mysqld_multi [OPTIONS] {start|reload|stop|report} [GNR-GNR,GNR,GNR-GNR,...]
4.启动默认的mysql实例--使用/etc/init.d/mysql start
~]# /etc/init.d/mysql start
Starting MySQL. [ OK ]
5.查看已经启动的mysql实例
~]# netstat -ntpl|grep 330
tcp 0 0 :::3306 :::* LISTEN 6643/mysqld
tcp 0 0 :::3307 :::* LISTEN 5667/mysqld
tcp 0 0 :::3308 :::* LISTEN 5666/mysqld
至此可以看到 在一台机器上启动了3个实例
6.连接不同的实例,用port区分
~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.11 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> Ctrl-C -- exit!
Aborted
~]# mysql -uroot -p -P3307
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.11 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> Ctrl-C -- exit!
Aborted
~]# mysql -uroot -p -P3308
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.6.11 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>
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27000195/viewspace-1419251/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/27000195/viewspace-1419251/