Mysqld_multi多实例
mysql多实例是指在一台服务器上同时运行多个mysqld进程,本文展示了多实例的部署过程,是通过单一配置文件和mysqld_multi命令进行简单管理;
1)准备参数文件/etc/my.cnf或者/etc/mysqld_multi.cnf
[root@db1 ~]# cat /etc/mysqld_multi.cnf
[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = multi_admin
password = multipass
[mysqld1]
port=3306
basedir=/usr
datadir=/data/mysql/data
socket=/data/mysql/mysql.sock
pid-file=/var/run/mysqld/mysqld.pid
log-error=/data/mysql/log/mysqld.log
user=mysql
[mysqld2]
port=3307
basedir=/usr
datadir=/data/mysql/data2
socket=/data/mysql/mysql2.sock
pid-file=/var/run/mysqld/mysqld2.pid
log-error=/data/mysql/log/mysqld2.log
user=mysql
2)初始化数据库
方法一:
mysql_install_db --datadir=/data/mysql/data --user=mysql
mysql_install_db --datadir=/data/mysql/data2 --user=mysql
mysql_install_db初始化数据的临时密码在~/.mysql_secret
方法二:
/usr/sbin/mysqld --initialize --datadir=/data/mysql/data2 --user=mysql
临时密码记录在log-error中(通常/var/log/mysqld.log)
/usr/sbin/mysqld --defaults-file=/etc/my.cnf --initialize --datadir=/data/mysql/data2 --user=mysql
方法三:
mysqld_multi start 2
(实际上也是mysql_install_db 初始化数据库)
3)创建multi_admin管理用户
mysql>create user multi_admin@localhost identified by 'multipass';
mysql>grant shutdown on *.* to multi_admin@localhost identified by ‘aa12AA,.’;
4)启动、停止多实例
mysqld_multi start 1
mysqld_multi start 2
mysqld_multi start 1,2
mysqld_multi start 1-2
mysqld_multi stop 1
mysqld_multi stop 2
mysqld_multi stop 1,2
mysqld_multi stop 1-2
mysqladmin -S /data/mysql/mysql2.sock -umulti_admin -p shutdown
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16976507/viewspace-2132775/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/16976507/viewspace-2132775/