mysql_multi 多实例

#安装mysql http://my.oschina.net/u/2492079/blog/521737

#复制启动脚本到 /etc/init.d
[root@166087 support-files]# cp mysqld_multi.server /etc/init.d/mysqld_multi

#修改启动路径
[root@166087 support-files]# vim /etc/init.d/mysqld_multi
basedir=/application/mysql
bindir=/application/mysql/bin

[root@166087 ~]# chmod +x  /etc/init.d/mysqld_multi
#初始化实例数据库
[root@166087 mysql] ./scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data_3307/ --user=mysql

#编辑配置文件
[root@166087 ~]# vim /etc/my.cnf
[mysqld_multi]
mysqld     = /application/mysql/bin/mysqld_safe
mysqladmin = /application/mysql/bin/mysqladmin
#注意,账号密码要写的,关闭数据要用到
#user       = mysql
#password   = my_password
[mysqld1]
socket     = /tmp/mysql1.sock
port       = 3306
pid-file   = /tmp/mysql1.pid
datadir    = /application/mysql/data
#language   = /usr/local/mysql/share/mysql/english
user       = mysql
[mysqld2]
socket     = /tmp/mysql2.sock
port       = 3307
pid-file   = /tmp/mysql2.pid
datadir    = /application/mysql/data_3307
#language   = /usr/local/mysql/share/mysql/english
user       = mysql

#启动所有实例
[root@166087 ~]# /etc/init.d/mysqld_multi start
WARNING: my_print_defaults command not found.
Please make sure you have this command available and
in your path. The command is available from the latest
MySQL distribution.
ABORT: Can't find command 'my_print_defaults'.
This command is available from the latest MySQL
distribution. Please make sure you have the command
in your PATH.

#要导入mysql bin目录到系统变量
[root@166087 ~]# export PATH=/application/mysql/bin:$PATH
[root@166087 ~]# /etc/init.d/mysqld_multi start
[root@166087 ~]# ps -ef | grep mysqld
root     13779     1  0 07:40 ?        00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --socket=/tmp/mysql1.sock --port=3306 --pid-file=/tmp/mysql1.pid --datadir=/application/mysql/data --user=mysql
mysql    14041 13779  0 07:40 ?        00:00:00 /application/mysql5.5/bin/mysqld --basedir=/application/mysql5.5 --datadir=/application/mysql/data --plugin-dir=/application/mysql5.5/lib/plugin --user=mysql --log-error=/application/mysql/data/166087.sys.ipv4.io.err --pid-file=/tmp/mysql1.pid --socket=/tmp/mysql1.sock --port=3306
root     14229     1  0 08:04 pts/0    00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --socket=/tmp/mysql2.sock --port=3307 --pid-file=/tmp/mysql2.pid --datadir=/application/mysql/data_3307 --user=mysql
mysql    14467 14229  0 08:04 pts/0    00:00:00 /application/mysql5.5/bin/mysqld --basedir=/application/mysql5.5 --datadir=/application/mysql/data_3307 --plugin-dir=/application/mysql5.5/lib/plugin --user=mysql --log-error=/application/mysql/data_3307/166087.sys.ipv4.io.err --pid-file=/tmp/mysql2.pid --socket=/tmp/mysql2.sock --port=3307
root     14486 14183  0 08:04 pts/0    00:00:00 grep mysqld

#单个实例启动和关闭
[root@166087 ~]# /etc/init.d/mysqld_multi stop 2
[root@166087 ~]# ps -ef | grep mysqld
root     13779     1  0 07:40 ?        00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --socket=/tmp/mysql1.sock --port=3306 --pid-file=/tmp/mysql1.pid --datadir=/application/mysql/data --user=mysql
mysql    14041 13779  0 07:40 ?        00:00:00 /application/mysql5.5/bin/mysqld --basedir=/application/mysql5.5 --datadir=/application/mysql/data --plugin-dir=/application/mysql5.5/lib/plugin --user=mysql --log-error=/application/mysql/data/166087.sys.ipv4.io.err --pid-file=/tmp/mysql1.pid --socket=/tmp/mysql1.sock --port=3306
root     14504 14183  0 08:04 pts/0    00:00:00 grep mysqld

#查看启动日志
[root@166087 ~]# cat /application/mysql/share/mysqld_multi.log


你可能感兴趣的:(多实例,mysql_multi)