首页 > 代码库 > mysqld_multi 多实例启动mysql

mysqld_multi 多实例启动mysql

假设服务器之前有一个3306的实例在运行了,我们要再添加一个3316端口的实例。


直接编辑 /etc/my.cnf ,添加如下内容(红色部分是后添加的配置项):

[client]

user= root

socket= /tmp/mysql.sock

port= 3306

 

[mysql]

prompt= ‘[\d] > ‘

 

[mysqld]

datadir=/bdata/data/nowdb2

socket= /tmp/mysql.sock

user=mysql

port= 3306

character-set-server= utf8

default_storage_engine= InnoDB

transaction_isolation  = READ-COMMITTED

skip_name_resolve= ON

skip_external_locking

query_cache_type= OFF

query_cache_size= 0

server-id= 11

log-bin= mysql.bin

binlog_format= ROW

log_error= /bdata/data/nowdb2/error.log

innodb_file_per_table   = ON

 

 

[mysqld_multi]

mysqld = /usr/local/mysql/bin/mysqld_safe

log = /var/log/mysqld_multi.log

 

[mysqld2]

datadir=/data/mysql2

socket = /tmp/mysql2.sock

user=mysql

port = 3316

character-set-server = utf8

default_storage_engine = InnoDB

transaction_isolation  =READ-COMMITTED

skip_name_resolve = ON

skip_external_locking

server-id = 106

log-bin = mysql-bin

slow_query_log = ON

slow_query_log_file = /data/mysql2/localhost_slow.log

long_query_time = 5

log_error = /data/mysql2/error.log

innodb_file_per_table   = ON

innodb_flush_log_at_trx_commit = 1

sync_binlog = 1

innodb_support_xa = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

symbolic-links=0

relay_log_info_repository = table

master_info_repository = table

relay_log_recovery = ON

 

[mysqld_safe]

log-error=/var/log/mysqld.log

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

 

[mysqldump]

quick

max_allowed_packet= 64M

 

初始化3316实例:

/usr/local/mysql/scripts/mysql_install_db--user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql2/

 

启动3316实例:

mysqld_multireport

mysqld_multistart 3316 即可启动3316实例。


同样的方法,可以再配置其他的mysql实例。


关闭的话,建议使用mysqladmin 即可。


注意,mysqld_mulit和原来的mysqld的启动停止没有任何关系。我们可以关闭/etc/init.d/mysqld,对mysqld_multi启动的实例没有任何影响。

mysqld_multi 多实例启动mysql