安装mysql
初始化两个数据库目录
mysql_install_db --datadir=/usr/local/var/mysql1 --user=mysql
mysql_install_db --datadir=/usr/local/var/mysql2 --user=mysql
修改数据库目录属性
chown -R mysql /usr/local/var/mysql1
chown -R mysql /usr/local/var/mysql2
制作多实例启动服务
cp /usr/share/mysql/mysqld_multi.server /etc/init.d/mysqld_multi.server
创建配置文件
vi /etc/mysql/mysqld_multi.cnf
[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
[mysqld3306]
port = 3306
socket = /var/run/mysqld/mysqld3306.sock
pid-file =/var/run/mysqld/mysqld3306.pid
datadir = /usr/local/var/mysql1
user =mysql
[mysqld3307]
port = 3307
socket = /var/run/mysqld/mysqld3307.sock
pid-file =/var/run/mysqld/mysqld3307.pid
datadir = /usr/local/var/mysql2
user =mysql
启动多实例
启动全部实例
mysqld_multi --defaults-file=/etc/mysql/mysqld_multi.cnf start
启动指定实例
mysqld_multi --defaults-file=/etc/mysql/mysqld_multi.cnf start 3306
关闭
关闭全部实例
mysqld_multi --defaults-file=/etc/mysql/mysqld_multi.cnf stop
关掉指定实例
mysqld_multi --defaults-file=/etc/mysql/mysqld_multi.cnf stop 3306
连接
mysql -uroot -S /var/run/mysqld/mysqld3306.sock
mysql -uroot -S /var/run/mysqld/mysqld3307.sock