同时运行两个mysql实例

运行环境: Ubuntu 6.06 server

1. 修改/etc/mysql/my.cnf

加入

[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = multi_admin
password = multipass

把原来的[mysqld]改成[mysqld001],并加入[mysqld002],分别配置两个实例,主要是下面这些设置要不同:

  • pid-file
  • socket
  • port
  • datadir

2. 设置用户

$ mysql -u root -S /var/run/mysqld/mysqld.sock -p
> GRANT SHUTDOWN ON *.* TO 'multi_admin'@'localhost' IDENTIFIED BY 'multipass';
$ mysql -u root -S /var/run/mysqld/mysqld2.sock -p
> GRANT SHUTDOWN ON *.* TO 'multi_admin'@'localhost' IDENTIFIED BY 'multipass';

3. 测试启动停止命令

$ mysqld_multi --no-log --config-file=/etc/mysql/my.cnf start 001,002
$ mysqld_multi --no-log --config-file=/etc/mysql/my.cnf stop 001,002
$ mysqld_multi --no-log --config-file=/etc/mysql/my.cnf report 001,002

4. 新建启动脚本 /etc/init.d/mysql-multi替换原来的启动脚本/etc/init.d/mysql

5. 修改/etc/phpmyadmin/config.inc.php,配置如何连接这两个服务器

$i = 0;
$i++;
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['socket'] = '/var/run/mysqld/mysqld.sock';
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['verbose'] = 'localhost:3306';
$i++;
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['socket'] = '/var/run/mysqld/mysqld2.sock';
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['verbose'] = 'localhost:3307';