【问题标题】:Strange MySQL replication update error (Magento)奇怪的 MySQL 复制更新错误(Magento)
【发布时间】:2015-03-31 17:20:51
【问题描述】:

MySQL 复制对我来说有点新意,但看起来我已经完成了它,直到出现一些我不理解的错误。

一些背景知识:我正在将所有数据库(通过 SSL)从 MySQL 5.6.22 服务器复制到 MariaDB 10.0.15 服务器,除了作为主服务器的专用从属服务器之外没有做任何其他事情。它执行了一些查询,但随后遇到了 Magento 数据库的更新问题。如果我跳过这个查询,它只会遇到一个导致相同错误的类似查询。

这是奴隶状态给我的错误:

无法在表 magento_db.log_visitor 上执行 Update_rows 事件;列“visitor_id”不能为空,错误代码:1048;在 'log_visitor' 中找不到记录,Error_code: 1032;列“visitor_id”不能为空,错误代码:1048;处理程序错误 HA_ERR_KEY_NOT_FOUND;事件主日志 mysql-bin.000121, end_log_pos 7656

Exec_Master_Log_Pos 是 7215,但我认为这无关紧要,错误出现在下一个查询(/事务块)中。

这是一段(详细的)mysqlbinlog:

COMMIT/*!*/;
# at 7215
#150330  2:19:45 server id 1  end_log_pos 7292 CRC32 0xf975481b 	Query	thread_id=25	exec_time=0	error_code=0
SET TIMESTAMP=1427674785/*!*/;
BEGIN
/*!*/;
# at 7292
# at 7358
#150330  2:19:45 server id 1  end_log_pos 7358 CRC32 0x0312921e 	Table_map: `magento_db`.`log_url_info` mapped to number 2528
#150330  2:19:45 server id 1  end_log_pos 7497 CRC32 0xe3704a8b 	Write_rows: table id 2528 flags: STMT_END_F
### INSERT INTO `magento_db`.`log_url_info`
### SET
###   @1=12534083 /* LONGINT meta=0 nullable=0 is_null=0 */
###   @2='http://www.myshop.com/catalog/category/view/id/29?cat=31&color=22&dir=desc&order=position&price=9-' /* VARSTRING(765) meta=765 nullable=1 is_null=0 */
###   @3=NULL /* VARSTRING(765) meta=765 nullable=1 is_null=1 */
# at 7497
# at 7565
#150330  2:19:45 server id 1  end_log_pos 7565 CRC32 0x340012cd 	Table_map: `magento_db`.`log_visitor` mapped to number 2513
#150330  2:19:45 server id 1  end_log_pos 7656 CRC32 0xd3d2e26f 	Update_rows: table id 2513 flags: STMT_END_F
### UPDATE `magento_db`.`log_visitor`
### WHERE
###   @1=3036630 /* LONGINT meta=0 nullable=0 is_null=0 */
### SET
###   @2='deq65v4ks7tgahp2lvih8s74j1' /* VARSTRING(192) meta=192 nullable=0 is_null=0 */
###   @3=1427667585 /* TIMESTAMP(0) meta=0 nullable=1 is_null=0 */
###   @4=1427667585 /* TIMESTAMP(0) meta=0 nullable=0 is_null=0 */
###   @5=12534083 /* LONGINT meta=0 nullable=0 is_null=0 */
###   @6=1 /* SHORTINT meta=0 nullable=0 is_null=0 */
# at 7656
# at 7714
#150330  2:19:45 server id 1  end_log_pos 7714 CRC32 0xc1eee09b 	Table_map: `magento_db`.`log_url` mapped to number 2529
#150330  2:19:45 server id 1  end_log_pos 7770 CRC32 0xf7bcccad 	Write_rows: table id 2529 flags: STMT_END_F
### INSERT INTO `magento_db`.`log_url`
### SET
###   @1=12534083 /* LONGINT meta=0 nullable=0 is_null=0 */
###   @2=3036630 /* LONGINT meta=0 nullable=1 is_null=0 */
###   @3=1427667585 /* TIMESTAMP(0) meta=0 nullable=0 is_null=0 */
# at 7770
#150330  2:19:45 server id 1  end_log_pos 7801 CRC32 0x51775dd4 	Xid = 29537
COMMIT/*!*/;
# at 7801
#150330  2:19:53 server id 1  end_log_pos 7886 CRC32 0xd6d724c7 	Query	thread_id=26	exec_time=0	error_code=0
SET TIMESTAMP=1427674793/*!*/;

visitor_id 是 phpMyAdmin 中显示的第一列,但在我执行 SHOW COLUMNS FROM log_visitor; 时也是如此,所以我猜测此列映射到“@1”(找不到如何验证这一点)。但是当我搜索visitor_id 3036630 的记录时,它只会找到一个。请注意,这不是由于外部查询,当我再次执行START SLAVE; 时,它会挂起相同的错误。另外,我尝试在从属服务器上运行 mysql_upgrade,但除了一些警告之外,这没有解决任何问题。

底线是:我不知道如何解释这个错误,我是否可能查看了错误的查询?我觉得应该没有错误,也许是一些不兼容?

欢迎提出任何建议!

编辑:根据要求,一个 SHOW CREATE TABLE,在进行差异后在两台服务器上看起来都一样,除了增量索引:

CREATE TABLE `log_visitor` (
 `visitor_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Visitor ID',
 `session_id` varchar(64) NOT NULL COMMENT 'Session ID',
 `first_visit_at` timestamp NULL DEFAULT NULL COMMENT 'First Visit Time',
 `last_visit_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Last Visit Time',
 `last_url_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT 'Last URL ID',
 `store_id` smallint(5) unsigned NOT NULL COMMENT 'Store ID',
 PRIMARY KEY (`visitor_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3036631 DEFAULT CHARSET=utf8 COMMENT='Log Visitors Table'

slave 是通过删除所有数据库创建的(我已经多次尝试),在获取 master 上的读锁后对所有数据库执行 mysqldump,将其导入从属,然后在正确的位置启动从属。它会进行一些查询,当我查看时,它已经出现了类似于此处描述的更新错误。

【问题讨论】:

  • 两个数据库中的表模式是否完全相同?这些错误表明,由于列定义的差异,适用于 master 的更新在 slave 上不起作用。
  • 请提供SHOW CREATE TABLE
  • 更新了问题,因为我显然已经注销了
  • 难道从服务器在“查询”中也需要一个显式的 @1 值?像“WHERE @1 SET @1 - @6”而不是“WHERE @1 SET @2 - @6”,即使@1 将保持不变。有些不兼容?

标签: mysql magento replication mariadb


【解决方案1】:

看来我找到了解决方案。我曾经为 master 复制/调整了一个不错的 my.cnf,其中包括 MySQL 5.6 设置“binlog_row_image = MINIMAL”。这会导致 binlog 跳过 UPDATE 的 SET 子句中的列,这些列已经在 WHERE 子句中并且未更改。 MariaDB 似乎没有实现这个设置,默认的 binlog ROW 格式要求所有字段都有一个值。

【讨论】:

    猜你喜欢
    • 2010-12-24
    • 1970-01-01
    • 2011-09-13
    • 1970-01-01
    • 2015-09-21
    • 2013-09-03
    • 2016-05-28
    • 2011-08-17
    • 2023-03-14
    相关资源
    最近更新 更多