同时运行两个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';

Leave a Reply

Your email address will not be published. Required fields are marked *

*

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.
For more help see http://daringfireball.net/projects/markdown/syntax

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>