日期:2014-05-16  浏览次数:20775 次

MySql配置主从复制 读写分离

?

mysql版本:5.6.13

OS:windows server 2008

Master 配置

?

my.ini配置文件中

主从复制需要通过二进制日志文件进行,须开启二进制日志功能并配置Server ID

?

[mysqld]
log-bin=mysql-bin
server-id=1

server-id 为1-232?-1? 之间,默认为0(拒绝所有slave

?

innodb引擎耐用性增强

innodb_flush_log_at_trx_commit=1?and?sync_binlog=1

?

For the greatest possible durability and consistency in a replication setup using?InnoDB?with transactions, you should use?innodb_flush_log_at_trx_commit=1?and?sync_binlog=1?in the master?my.cnf?file.

?

?slave 配置

server-id=2

防止服务器主机名修改

?relay-log=mysqld-relay-bin

?

master

创建具有复制权限的账户repl

GRANT REPLICATION SLAVE ON *.*
-> TO 'repl'@'remotehost.mydomain.com' IDENTIFIED BY 'slavepass';

?

mysql> FLUSH TABLES WITH READ LOCK;

对于InnoDB