当前位置:Gxlcms > mysql > ubuntumysql5.6安装与双机热备有关问题及解决方案汇总2

ubuntumysql5.6安装与双机热备有关问题及解决方案汇总2

时间:2021-07-01 10:21:17 帮助过:52人阅读

ubuntu mysql 5.6 安装与双机热备 问题及解决方法汇总2 主机配备salve: 主机上 Mysql 执行: grant replication slave on *.* to slave@'172.36.8.%' identified by 'passwd'; 修改主从配置: 1)主机操作 #mysql -uroot -passwd mysqlcreate database yccs_

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 ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.。。
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000006
Read_Master_Log_Pos: 120
Relay_Log_File: ubuntu-relay-bin.000002
Relay_Log_Pos: 283
Relay_Master_Log_File: mysql-bin.000006
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: DATABASE
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 120
Relay_Log_Space: 457
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 8750084d-3197-11e3-863d-0050569b1e91
Master_Info_File: /opt/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)

ERROR:
No query specified

主从同步问题已经解决;

人气教程排行