mysql主从配置

来源:互联网 发布:希拉里的女儿 知乎 编辑:程序博客网 时间:2024/06/15 22:33

参考

http://www.cnblogs.com/future2012lg/p/4873805.html

主配置

修改my.ini文件,在[mysqld]下增加以下配置:

#主服务器二进制日志文件前缀名log-bin=master-bin#索引文件log-bin-index=master-bin.index#开启innodb的一表一个文件的设置innodb_file_per_table=1#必须是唯一的server-id=1#忽略复制的dbbinlog-ignore-db=information_schemabinlog-ignore-db=mysqlbinlog-ignore-db=performance_schemabinlog-ignore-db=sysbinlog_format=mixed#在主服务器上进行设置,用于事务安全sync-binlog=1

增加同步数据账户

grant replication slave on *.* to 'repl'@'%' identified by '123456';flush privileges;

重启主mysql服务

连上主mysql后输入

show master status;

记录file,position字段,后面从开启复制用

从配置

修改my.ini文件,在[mysqld]下增加以下配置:

#设置中继日志relay-log=relay-log#中继日志索引relay-log-index=relay-log.index#id不要和主服务器的一样server-id=2#设置非管理员组只读read-only=ON

重启从mysql服务

连上从mysql后输入

change master to master_host='127.0.0.1',master_port=3307,master_user='repl',master_password='123456',master_log_file='master-bin.000001',master_log_pos=154;

输入show slave status\G可以查看状态

start slave;

主主配置

即互为主从即可

前面的配置为前两个mysql,此为第三个mysql

#主服务器二进制日志文件前缀名log-bin=master-bin#索引文件log-bin-index=master-bin.index#开启innodb的一表一个文件的设置innodb_file_per_table=1#必须是唯一的server-id=3#忽略复制的dbbinlog-ignore-db=information_schemabinlog-ignore-db=mysqlbinlog-ignore-db=performance_schemabinlog-ignore-db=sysbinlog_format=mixed#在主服务器上进行设置,用于事务安全sync-binlog=1#设置中继日志relay-log=relay-log#中继日志索引relay-log-index=relay-log.indexauto-increment-increment=2auto-increment-offset=2

增加同步数据账户

grant replication slave on *.* to 'repl'@'%' identified by '123456';flush privileges;

重启主mysql服务

连上主mysql后输入

show master status;

记录file,position字段,后面从开启复制用

change master to master_host='127.0.0.1',master_port=3307,master_user='repl',master_password='123456',master_log_file='master-bin.000001',master_log_pos=154;

输入show slave status\G可以查看状态

start slave;

第一台主mysql配置

#主服务器二进制日志文件前缀名log-bin=master-bin#索引文件log-bin-index=master-bin.index#开启innodb的一表一个文件的设置innodb_file_per_table=1#必须是唯一的server-id=1#忽略复制的dbbinlog-ignore-db=information_schemabinlog-ignore-db=mysqlbinlog-ignore-db=performance_schemabinlog-ignore-db=sysbinlog_format=mixed#在主服务器上进行设置,用于事务安全sync-binlog=1#设置中继日志relay-log=relay-log#中继日志索引relay-log-index=relay-log.indexauto-increment-increment=2auto-increment-offset=1

重启主mysql服务

连上主mysql后输入

show master status;

记录file,position字段,后面从开启复制用

change master to master_host='127.0.0.1',master_port=3309,master_user='repl',master_password='123456',master_log_file='master-bin.000001',master_log_pos=154;

输入show slave status\G可以查看状态

start slave;
0 0
原创粉丝点击