Mysql 主从报错

xiaoxiao2021-02-28  86

1、在从库上面show slave status\G;出现下列情况,   Slave_IO_Running: Yes   Slave_SQL_Running: No   Seconds_Behind_Master: NULL 原因:程序可能在 slave 上进行来写操作;slave 机器重启后,事务会滚造成;同步过程中遇到某种错误,如果是这种情况,在查看从库状态的时候会看到错误提示。 解决:进入 master;show master status; 然后去 slave 端执行手动同步。 slave stop change master to  master_host='...', master_user='...', master_passwd='', master_port=3306 ...... 2、slave 数据库无法同步   show slave status显示:   Slave_IO_Running: No   Slave_SQL_Running: Yes   Seconds_Behind_Master: NULL 原因:master 数据库存在问题,由于连接主库信息错误、主库数据库挂掉如果说常见错等原因引起的,在实际的操作中先重启master后重启slave即可解决这问题,出现此问题,必须要要重启master数据库。 解决:首先查看数据库的err日志,查看是什么错误提示,看从库连接主库的IP、用户、密码等相关信息是否有误,如果有误,重新执行同步;如果确认无误,重启主数据库。 mysql> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 98 | adb| mysql| +------------------+----------+--------------+------------------+ 进入从库mysql,执行: slave stop; change master to Master_Log_File='mysql-bin.000001',Master_Log_Pos=98; slave start; 或是这样: stop slave; set global sql_slave_skip_counter =1; start slave; 3、和第二题类似,重点看看解决思路 server_errno=1236 show slave status\G; Slave_IO_Running: NO  Slave_SQL_Running: Yes ...  Last_Errno: 0  Last_Error: ... Seconds_Behind_Master: NULL 排错:查看错误日志 090605 9:13:20 [Note] Slave SQL thread initialized, starting replication in log ‘mysql-bin.000102′ at position 1029244974, relay log ‘./xxx-relay-bin.000634′ position: 98 090605 9:13:20 [Note] Slave I/O thread: connected to master ’slave163@192.168.0.131:3306′, replication started in log ‘mysql-bin.000102′ at position 1029244974 090605 9:13:20 [ERROR] Error reading packet from server: Client requested master to start replication from impossible position ( server_errno=1236) 090605 9:13:20 [ERROR] Got fatal error 1236: ‘Client requested master to start replication from impossible position’ from master when reading data from binary log 090605 9:13:20 [Note] Slave I/O thread exiting, read up to log ‘mysql-bin.000102′, position 1029244974 090605 9:13:52 [Note] Error reading relay log event: slave SQL thread was killed 原因:mysql-bin.000102 文件中么有 1029244974 这个位置,服务器请求一个错误的位置而引起。 解决原理: 从相关的BIN LOG 里最后一个日志位置,与从服务器上的日志对比,如果LOG里最后位置比错误的位置大,那么,说明中间可能有断点,需要把从服务器的位置向前调,多试几次.如果在LOG里最后的位置比从服务器指出的位置还小,那么只要把从服务器的位置设置成LOG的最后位置就可以了. 解决:1、slave stop;grant master to master_log_file='mysql-bin.000103', master_log_pos=0;      注意解决方法是重新同步,如果是按照上面的方法,跳过不再的位置,直接同步下一个文件000103,那么就可能造成主从信息不一致,最好是从之前的位置同步      grant master to master_log_file='000102',master_log_pos='1019244974'      2、在 my.cnf 中加 slave-skip-errors 参数,否则会报主键重复的错误 4、报错 Slave_IO_Running: No   Slave_SQL_Running: Yes Last_IO_Error: error connecting to master 'repl@127.0.0.1:3306' - retry-time: 60 retries: 86400 原因:可能是主库和从库的 bin-log 一项不匹配, 解决:修改 bin-log 配置 >>> 重启服务 >>> 进入从库 >>> slave stop; change ...; slave start; show slave status; 5、slave 端报错 Last_IO_Error: error connecting to master 'slaveuser2@192.168.32.142:3306' - retry-time: 60 retries: 86400 原因:不能连接 master,master 授权错误;slave 密码输错 排查:master 端, show grants for 'slaveuser2'@'%';  查看是否是授权语句错误,注意这里看不出密码是多少,已经加密。 slave端, mysql -uslaveuser2 -P3306 -h 192.168.32.142 -p  输入密码,如果提示 denied by host,说明密码不对, 解决:重新授权密码,或者在master 端上翻出命令,查看密码是多少。 6、主从不能同步show slave status\G: Slave_SQL_Running: NO Seconds_Behind_Master: NULL Error xxx dosn't exist 原因:缺少某个具体的数据导致信息不能同步 解决: slave stop;  set globle sql_slave_skip_counter = 1; slave start; 说明:SET GLOBAL SQL_SLAVE_SKIP_COUNTER=n  该命令在客户端运行,用来跳过几个事件,只有当同步进程出现错误而停止的时候才可以执行。 7、同步过程出现重复现象Last-Errno: 1062 Last-Error: Error 'Duplicate entry '15386' for key 1' on query. Default database: 'db'. Query: 'INSERT INTO db.table ( FIELDS ) VALUES ( VALUES )'  键重复了,必须跳过才能继续。 原因: slave 开始复制数据的 position 已经存在,键发生重复 解决: 跳过该步骤,slave stop; set global sql_slave_skip_counter=1; slave start;       配置文件 /etc/my.cnf 中写入 --slave-skip-errors=[err_code1,err_code2....] 8、 No argument was provided to –log-bin, and –log-bin-index was not used; so replication may break when this MySQL server acts as a master and has his hostname changed!! Please use ‘–log-bin=mysql-bin’ to avoid this problem.      Neither –relay-log nor –relay-log-index were used; so replication may break when this MySQL server acts as a slave and has his hostname changed!! Please use ‘–relay-log=mysql-relay-bin’ to avoid this problem. 在my.cnf 的[mysqld]中加入 log-bin=mysql-bin 在my.cnf 的[mysqld]中加入 relay-log=mysql-relay-bin 9、 [ERROR] The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the –replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it). 在 my.cnf 中的 [mysqld] 中加入 replicate-same-server-id,但是如错误信息所示,该方法并不总是有效,最好修改 server-id 10、[Note] Slave I/O thread: connected to master ‘test@:3306′,replication started in log ‘FIRST’ at position 4 [ERROR] Error reading packet from server: Access denied; you need the REPLICATION SLAVE privilege for this operation ( server_errno=1227) 可能是原来使用过 slave 连接,需要将 mysql 库中的 master.info 删除 11、从库 slave 启动错误  Could not initialize master info structure; more error messages can be found in the MySQL error log. 原因:初始化 master info 结构失败 解决方法: 1、查看MySQL错误日志,如:同步的上一个Position是多少,很多情况下无法启动服务是由于mysql识别的同步始终停留在上一个Position上。 2、查看master.info和relay-log.info,master.info 记录MASTER相关信息,relay-log.info 记录当前同步日志信息。 3、停止myslq服务,删除master.info和relay-log.info。 4、启动mysql服务。 5、重新CHANGE MASTER,重新启动SLAVE服务。 12、主从信息变更导致错误130311 14:15:46 mysqld started 130311 14:15:46 [Warning] option 'read_rnd_buffer_size': unsigned value 0 adjusted to 8200 130311 14:15:47 InnoDB: Started; log sequence number 15 2381115047 130311 14:15:47 [ERROR] Failed to open the relay log './localhost-relay-bin.000037' (relay_log_pos 52474065) 130311 14:15:47 [ERROR] Could not find target log during relay log initialization 130311 14:15:47 [ERROR] Failed to initialize the master info structure 130311 14:15:47 [Note] /usr/local/mysql/libexec/mysqld: ready for connections. Version: '5.0.87-log' socket: '/var/tmp/mysql2.sock' port: 3308 Source distribution 原因:由于变更来 slave 的服务端口和文件路径,mysql-relay-bin.index 中仍然保持着旧 relay 日志文件的路径,这些路径找不到合适的文件,报错。 解决:reset slave; change master to master_host。。。。。 13、Warning: a page in the doublewrite buffer is not within space 原因:多为磁盘故障引起。
转载请注明原文地址: https://www.6miu.com/read-65295.html

最新回复(0)