ubuntu mysql 5.6 安装与双机热备 问题及解决方案汇总2
主机配备salve:
主机上 Mysql 执行:
grant replication slave on *.* to slave@'172.36.8.%' identified by 'passwd';
修改主从配置:
1)主机操作
#mysql -uroot -passwd
mysql>create database yccs_admin;
mysql>grant replication slave on *.* to 'root'@'192.168.0.124' identified by 'passwd';
编辑my.cny
在【mysqld】中去除下面注释:
servier-id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog-do-db= your_dbname //如果有多个数据库需要同步,重复此参数,每个数据库一行
binlog-ignore-db=mysql //不同步的数据库
重新启动mysql
service mysql restart
通过命令查看:
show master status ; //通过该命令获取file和position,这个在配置slave的时候有用
2)从机配置
编辑【mysqld】
server-id = 2
replicate-do-db=your_dbname
replicate-ignore-db=mysql
slave-skip-errors= 1062 //加上这条
从新启动mysql服务
service mysql restart
登录并创建数据库:
mysql -uroot -ppasswd
create database yccs_admin;
3)在主从服务器上执行
主: mysql> flush master; flush logs;
从:mysql> flush slave; flush logs;
4)在从服务器上执行如下命令
mysql>stop slave;
mysql>change master to master_host='192.168.0.123',master_user=’root',master_password='passwd',master_port=3306,
master_log_file='mysql-bin.000001',master_log_pos=107;
mysql>start slave;
mysql>show slave status\G
如果slave_IO_running:yes slave_sql_running:yes,那说明没有问题了,就可以再主机上面建库建表写测试数据了,然后
在从机器上查看有没有数据同步过来。
期间会遇到一些问题:
从机上执行:
show slave status\G;
Last_IO_Errno: 1236
Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'binlog truncated in the middle of event; consider out of disk space on master; the first event 'mysql-bin.000001' at 107, the last event read from '/var/log/mysql/mysql-bin.000001' at 107, the last byte read from '/var/log/mysql/mysql-bin.000001' at 126.'
Last_SQL_Errno: 0
Last_SQL_Error:
ERROR:
mysql主从库不同步解决方法
遇到这样的错误如:“Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'”等或由于清数据导致主从库不同步了,解决办法如下:
先进入slave中执行:"slave stop;"来停止从库同步;
再去master中执行:"flush logs;"来清空日志;
然后在master中执行:"show master status;"查看下主库的状态,主要是日志的文件和position;
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000006 | 120 | DATABASSE | mysql | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
然后回到slave中,执行:"CHANGE MASTER TO MASTER_LOG_FILE='log-bin.000004',MASTER_LOG_POS=106;",文件和位置对应master中的;
最后在slave中执行:"slave start;"来启动同步。
当你幸福的时候,我不在,当我幸福的时候,你也不在
change master to master_host='172.16.8.66',master_user='root',master_password='PASSWD',master_port=3306,master_log_file='mysql-bin.000006',master_log_pos=120;
mysql> show slave status\G;
*************************** 1. row ************************