mysql多实例配置
 就是在一台服务器上运行多个mysql实例,每个实例需要一个独立的端口,实例的配置可以按实际需求进行设置

 
1、配置mysql多实例
 # vim /etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = mysql
log = /database/log/mysqld-muti.log

join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M

query_cache_type = on
query_cache_size = 128M
query_cache_limit = 128M
character_set_server = utf8

explicit_defaults_for_timestamp = on
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld1]
port = 3306
datadir = /database/data1
socket = /tmp/mysql1.sock
log_error = /database/data1/error.log
log_bin = /database/data1/mysqld1-bin
binlog_format = row
server_id = 1

expire_logs_days = 60
binlog_cache_size = 64M

[mysqld2]
port = 3307
datadir = /database/data2
socket = /tmp/mysql2.sock
log_error = /database/data2/error.log
log_bin = /database/data2/mysqld2-bin
binlog_format = statement
server_id = 2
expire_logs_days = 30
binlog_cache_size = 64M
 
 
 [mysqld3]
port = 3308
datadir = /database/data3
socket = /tmp/mysql3.sock
log_error = /database/data3/error.log
log_bin = /database/data3/mysqld3-bin
binlog_format = rmixed
server_id = 3
expire_logs_days = 30
binlog_cache_size = 64M
2、初始化数据库

linux下my.cnf配置文件的搜索路径为:/etc/my.cnf./etc/mysql/my.cnf /usr/local/mysql/my.cnf,~/my.cnf
cd /usr/local/mysql
# ./scripts/mysql_install_db --user=mysql --datadir=/database/data1
# ./scripts/mysql_install_db --user=mysql --datadir=/database/data2
# ./scripts/mysql_install_db --user=mysql --datadir=/database/data3

 
  3、多实例管理
# mysqld_multi report
# mysqld_multi start 1,2,3  \\启动实例1,2,3
# mysqld_multi start 1-3    \\启动实例1,2,3
# mysqld_multi --user=root stop 1-3   \\停止实例1,2,3

  4、连接到指定的服务器
# mysql -u root -S /tmp/mysql1.sock
# mysql -u root -h localhost -P 3307
# mysql -u root -h 127.0.0.1 -P3307