包下载http://url.cn/WrNg5S
主数据库:192.168.161.129
从数据库1:192.168.161.130
从数据库1:192.168.161.138
MySQL安装地址:/usr/local/mysql
MySQL数据目录:/usr/local/mysql/data
主MySQL二进制日志(binlog)文件:/usr/local/mysql/mysql-binlog
从MySQL中继日志文件:/usr/local/mysql/mysql-relay-binlog
1、创建复制帐号:
mysql>grant replication salve on *.* to ‘rep‘@‘192.168.161.%‘ identified by ‘mypassword‘;
如果只是单纯的一主多从,则只需要在主MySQL上建立这个帐号,考虑到以后可能需要做故障处理或切换主MySQL,从MySQL建立同样的帐号
2、修改主MySQL配置文件my.cnf
[mysqld]
server-id=129
log-bin=/usr/local/mysql/mysql-binlog
重启MySQL:service mysql restart
查看主MySQL状态:mysql>show master status;
File | Postion | Binlog_D0DB | Binlog_Ignore_DB | Executed_Gtid_Set |
mysql-binlog.000009 | 120 |
3、修改从MySQL配置文件my.cnf
[mysqld]
server-id=130(每个从MySQL的server-id必须不同)
log-bin=/usr/local/mysql/mysql-binlog
relay-log=/usr/local/mysql/relay-log
4、重启从MySQL,执行启动复制
mysql>change master to master_host=‘192.168.161.129‘,master_user=‘rep‘,master_password=‘mypassword‘,master_log_file=‘mysql-binlog.000009‘,master_log_pos=120;
mysql>start slave;
主从配置基本完成,可以在主MySQL创建表,看看从MySQL是否生成新表