msyql主从实际是从库上设置复制同步主库信息到从库,所有主库只需开启bing-log日志配置用户,然后在从库上开开启从库复制即可。
主库配置
service mysql restart
[mysqld]
server-id = 1
log_bin = /home/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
grant replication slave on *.* to 'ruobbo_slave'@'%' identified by '123456';
show master status;
文件名和行数字对应下面从库复制时sql里的值
从库配置
[mysqld]
server-id = 2
log-bin=relay-bin
relay-log-index = slave-replay-bin.index
change master to master_host='192.168.1.55',master_user='ruobbo_slave',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=63840458;
取消从库复制 reset slave;
启动从库复制 start slave;
关闭从库复制 start slave;
show slave status\G
测试在主库新增加一个条数据,看从库是否同步
关闭从库 stop slave;
删除主从复制
change master to master_host=' ';
在主库上同样设置下复制从库就是互为主从
清理主库bin-log日志
RESET MASTER;删除所有binlog日志,新日志编号从头开始
PURGE MASTER LOGS TO ‘mysql-bin.010’; ||删除mysql-bin.010之前所有日志
PURGE MASTER LOGS BEFORE ‘2003-04-02 22:46:26’; ||删除2003-04-02 22:46:26之前产生的所有日志
清理mysql错误日志
>/home/log/mysqld.log
用大于号清空linux文件内容