4、修改配置文件
suse11:~ # more /etc/my.cnf #本配置文件中仅提供了多实例的基本参数,生产环境根据情形自行添加
[mysqld_multi]
mysqld = /u01/app/mysql/bin/mysqld_safe
mysqladmin = /u01/app/mysql/bin/mysqladmin
user = admin #此帐户用于多实例关闭时使用,需要在每个实例上创建并授权
password = xxx #使用统一的密码便于管理
[mysqld3306]
socket = /tmp/mysql3306.sock
port = 3306
pid-file = /u01/app/mysqldata/data3306/mysql3306.pid
datadir = /u01/app/mysqldata/data3306
basedir = /u01/app/mysql
user = mysql
server-id=3306
[mysqld3406]
socket = /tmp/mysql3406.sock
port = 3406
pid-file = /u01/app/mysqldata/data3406/mysql3406.pid
datadir = /u01/app/mysqldata/data3406
basedir = /u01/app/mysql
user = mysql
server-id=3406
[mysqld3506]
socket = /tmp/mysql3506.sock
port = 3506
pid-file = /u01/app/mysqldata/data3506/mysql3506.pid
datadir = /u01/app/mysqldata/data3506
basedir = /u01/app/mysql
user = mysql
server-id=3506
5、启动关闭多实例
suse11:~ # mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3306 is not running
MySQL server from group: mysqld3406 is not running
MySQL server from group: mysqld3506 is not running
suse11:~ # mysqld_multi start 3306
suse11:~ # mysqld_multi start 3406,3506 #可以同时启动多个实例
suse11:~ # netstat -ntlp | grep mysql
tcp 0 0 :::3306 :::* LISTEN 14786/mysqld
tcp 0 0 :::3406 :::* LISTEN 15103/mysqld
tcp 0 0 :::3506 :::* LISTEN 15371/mysqld
suse11:/tmp # ls *.sock
mysql3306.sock mysql3406.sock mysql3506.sock
#为新实例修改密码及创建账户
suse11:/tmp # mysql -uroot -pxxx -S ./mysql3306.sock #3306已经有初始密码
root@localhost[(none)]> grant shutdown on *.* to 'admin'@'localhost' identified by 'xxx' with grant option;
suse11:/tmp # mysql -uroot -p -S ./mysql3406.sock
Enter password: #此时密码为空
root@localhost[(none)]> set password for 'root'@'localhost'=password('xxx');
root@localhost[(none)]> grant shutdown on *.* to 'admin'@'localhost' identified by 'xxx' with grant option;
suse11:/tmp # mysql -uroot -p -S ./mysql3506.sock
Enter password: #此时密码为空
root@localhost[(none)]> set password for 'root'@'localhost'=password('xxx');
root@localhost[(none)]> grant shutdown on *.* to 'admin'@'localhost' identified by 'xxx' with grant option;
#使用TCP方式登录测试
suse11:/tmp # mysql -uroot -pxxx -P3506
root@localhost[(none)]>
#检查多实例的状态
suse11:/tmp # mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3306 is running
MySQL server from group: mysqld3406 is running
MySQL server from group: mysqld3506 is running
#停止多实例服务器
suse11:~ # mysqld_multi stop 3306
suse11:~ # mysqld_multi report 3306
Reporting MySQL servers
MySQL server from group: mysqld3306 is not running
suse11:~ # mysqld_multi stop 3406
suse11:~ # mysqld_multi stop 3506