先说明下如此做的好处:

   1:充分利用单机的计算能力

  2:可以有效的分配不同的逻辑到不同的mysql提高数据库并行处理能力

  3:单机也可以方便的实现主从备份

安装方法:先装mysql(省略),比如yum安装的mysql

A:shell > mysqld_multi --example 将这个内容复制到vim /etc/mysqld_multi.cnf

核心更改:

[mysqld_multi]

mysqld     = /usr/bin/mysqld_safe

mysqladmin = /usr/bin/mysqladmin

user       = mysql

#password   = my_password


[mysqld1]

socket     = /var/lib/mysql/mysql.sock

port       = 3306

pid-file   = /var/run/mysqld/mysqld.pid

datadir    = /var/lib/mysql

#language   = /usr/share/mysql/english

user       = mysql




[mysqld2]

socket     = /tmp/mysql.sock2

port       = 3307

pid-file   = /var/run/mysqld/mysqld.pid2

datadir    = /var/lib/mysql2

#language   = /usr/share/mysql/english

user       = mysql


[mysqld3]

socket     = /tmp/mysql.sock3

port       = 3308

pid-file   = /var/run/mysqld/mysqld.pid3

datadir    = /var/lib/mysql3

#language   = /usr/share/mysql/english

user       = mysql


[mysqld4]

socket     = /tmp/mysql.sock4

port       = 3309

pid-file   = /var/run/mysqld/mysqld.pid4

datadir    = /var/lib/mysql4

#language   = /usr/share/mysql/english

user       = mysql


[mysqld5]

socket     = /tmp/mysql.sock5

port       = 3310

pid-file   = /var/run/mysqld/mysqld.pid5

datadir    = /var/lib/mysql5

#language   = /usr/share/mysql/english

user       = mysql

B. 复制data目录 并且赋权

shell > cp -R /var/lib/mysql var/lib/mysql2

shell > cp -R /var/lib/mysql var/lib/mysql3

shell > cp -R /var/lib/mysql var/lib/mysql4

shell > cp -R /var/lib/mysql var/lib/mysql5

shell > cd /var/lib/mysql

shell > chown -R mysql:mysql mysql* #赋权

核心命令:

查看multi启动状态

shell > mysqld_multi --defaults-extra-file=/etc/mysqld_multi.cnf report

启动指定端口的数据库

shell > mysqld_multi --defaults-extra-file=/etc/mysqld_multi.cnf start 2

[root@localhost lib]# mysqld_multi --defaults-extra-file=/etc/mysqld_multi.cnf report

Reporting MySQL servers

MySQL server from group: mysqld1 is running

MySQL server from group: mysqld2 is running

MySQL server from group: mysqld3 is running

MySQL server from group: mysqld4 is running

MySQL server from group: mysqld5 is running