CFG file is missing and source table is found to have row versions报错原因分析
参考:
https://docs.percona.com/percona-xtrabackup/8.0/error-message-instant.html
https://dev.mysql.com/doc/refman/8.0/en/innodb-table-import.html
https://jira.mariadb.org/browse/MDEV-20974
https://www.percona.com/blog/percona-xtrabackup-8-0-29-and-instant-add-drop-columns/
https://www.cnblogs.com/harda/p/17528512.html
https://ost.51cto.com/posts/24963
环境:mysql 8.0.32
操作:alter table xxx import tablespace
报错:
ERROR 1808 (HY000): Schema mismatch (CFG file is missing and source table is found to have row versions. CFG file is must to IMPORT tables with row versions.)
操作步骤:
先说下正常表迁移流程应该如何操作。
1、在源端执行 flush table xxxx for export 生成 cfg 文件。
2、到目标端创建表,并执行 alter table xxx discard tablespace。
3、将源端的 ibd 、cfg 文件同时拷贝到目标端数据目录,再源端执行 unlock tables 解锁。。
4、修改文件权限。
5、目标端执行 alter table xxx import tablespace
我的操作流程偷懒了,
1、在目标端创建表,并执行 alter table xxx discard tablespace。
2、从源端拷贝单个 ibd 文件到目标端数据目录。
3、修改文件权限,目标端执行 alter table xxx import tablespace。
然后就出现最开始的报错。
分析:
这个 cfg 文件并不是必须的,在 5.7 环境中以偷懒的方式操作过,没有问题,但在 8.0.32 版本中不行了。
提示源端表有 row 版本,开始以为是表 row_format 哪里的不一样,经过确认,都是一样的没有问题。
从 percona 网站上得到了些新思路,就是这个表经历过 DDL( instant )
复现报错:
源端实例操作:
mysql> create table t1(id int ,name varchar(200));
Query OK, 0 rows affected (0.02 sec)
mysql> insert into t1 select 1,'a';
Query OK, 1 row affected (0.01 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> insert into t1 select 1,'a';
Query OK, 1 row affected (0.01 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> insert into t1 select 1,'a';
Query OK, 1 row affected (0.01 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLES WHERE TOTAL_ROW_VERSIONS > 0;
Empty set (0.00 sec)
mysql> alter table t1 add age int;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> update t1 set age=10;
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLES WHERE TOTAL_ROW_VERSIONS > 0;
+--------+
| NAME |
+--------+
| czg/t1 |
+--------+
1 row in set (0.01 sec)
目标端实例操作:
mysql> CREATE TABLE `t1` (
-> `id` int DEFAULT NULL,
-> `name` varchar(200) COLLATE utf8mb4_general_ci DEFAULT NULL,
-> `age` int DEFAULT NULL
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
-> ;
Query OK, 0 rows affected (0.02 sec)
mysql> alter table t1 discard tablespace;
Query OK, 0 rows affected (0.01 sec)
--- 拷贝物理文件 t1.ibd 到数据目录
mysql> alter table t1 import tablespace;
ERROR 1808 (HY000): Schema mismatch (CFG file is missing and source table is found to have row versions. CFG file is must to IMPORT tables with row versions.)
mysql>
mysql>
解决问题。
因为源端表经历过DDL(INSTANT),表内有带 version 的行。将其转为常规表即可。
源端操作
mysql> alter table t1 engine=innodb;
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> SELECT NAME FROM INFORMATION_SCHEMA.INNODB_TABLES WHERE TOTAL_ROW_VERSIONS > 0;
Empty set (0.00 sec)
-- 拷贝 t1.ibd 文件到目标端,覆盖旧的 t1.ibd 文件。
mysql>
mysql> alter table t1 import tablespace;
Query OK, 0 rows affected, 1 warning (0.05 sec)
mysql> select * from t1;
+------+------+------+
| id | name | age |
+------+------+------+
| 1 | a | 10 |
| 1 | a | 10 |
| 1 | a | 10 |
+------+------+------+
3 rows in set (0.01 sec)
mysql>
mysql>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
2021-08-30 MySQL开启SSL加密
2021-08-30 MDL锁获取顺序和优先先
2021-08-30 explicit_defaults_for_timestamp 参数说明