mysqld_multi多实例运行
2016-05-04 TsengYia@126.com http://tsengyia.blog.chinaunix.net
#################################################################
系统环境:
RHEL 6.7 [2.6.32-573.el6.x86_64]
软件环境:
mysql-server-5.1.73-5.el6_6.x86_64
mysql-5.1.73-5.el6_6.x86_64
#################################################################
一、准备工作
1)装包
[root@svr5 ~]# yum -y install mysql-server mysql
2)设置管理口令
[root@svr5 ~]# service mysqld restart
[root@svr5 ~]# mysqladmin -u root password '新密码';
二、配置多实例
1)添加管理用户
[root@svr5 ~]# mysql -u root -p
Password:
mysql> GRANT SHUTDOWN ON *.* TO zyadm@localhost IDENTIFIED BY 'pwd123';
mysql> QUIT
[root@svr5 ~]#
2)为多个实例提供数据目录
[root@svr5 ~]# cp -prf /var/lib/mysql{,2,3}
[root@svr5 ~]# ls -ld /var/lib/mysql*
drwxr-xr-x. 4 mysql mysql 4096 5月 4 15:02 /var/lib/mysql
drwxr-xr-x. 4 mysql mysql 4096 5月 4 15:21 /var/lib/mysql2
drwxr-xr-x. 5 mysql mysql 4096 5月 4 15:29 /var/lib/mysql3
3)建立多实例配置文件
[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = multiadm
password = pwd123
[mysqld1]
socket = /tmp/mysql.sock
port = 3306
pid-file = /var/lib/mysql/mysqld.pid
datadir = /var/lib/mysql
user = mysql
[mysqld2]
socket = /tmp/mysql2.sock
port = 3307
pid-file = /var/lib/mysql2/mysqld.pid
datadir = /var/lib/mysql2
user = mysql
[mysqld3]
socket = /tmp/mysql3.sock
port = 3308
pid-file = /var/lib/mysql3/mysqld.pid
datadir = /var/lib/mysql3
user = mysql
三、多实例的进程控制
1)控制所有实例
mysqld_multi start
mysqld_multi stop
mysqld_multi report
2)控制部分实例
mysqld_multi start [GNR[,GNR]...]
mysqld_multi stop [GNR[,GNR]...]
mysqld_multi report [GNR[,GNR]...]
—— 其中GNR表示实例编号,例如2
—— 同时控制多个实例,可用逗号分隔(如1,3),或连续范围(如1-3)
四、访问不同的实例
mysql -S /tmp/mysql.sock -u root -p
mysql -S /tmp/mysql2.sock -u root -p
mysql -S /tmp/mysql3.sock -u root -p
或者
mysql --protocol TCP -h localhost -P 3306 -u root -p
mysql --protocol TCP -h localhost -P 3307 -u root -p
mysql --protocol TCP -h localhost -P 3308 -u root -p
#################################################################
参考:http://blog.chinaunix.net/uid-20639775-id-3438560.html
阅读(987) | 评论(0) | 转发(0) |