Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql 8 ,备份包含json字段的表时报错 #46

Open
liuyuanjun opened this issue Dec 13, 2024 · 6 comments
Open

mysql 8 ,备份包含json字段的表时报错 #46

liuyuanjun opened this issue Dec 13, 2024 · 6 comments

Comments

@liuyuanjun
Copy link

Traceback (most recent call last):
File "/root/ibd2sql-main/main.py", line 204, in
ddcw.get_sql()
File "/root/ibd2sql-main/ibd2sql/ibd2sql.py", line 256, in get_sql
for x in _tdata:
File "/root/ibd2sql-main/ibd2sql/innodb_page_index.py", line 359, in read_row
self._read_all_row()
File "/root/ibd2sql-main/ibd2sql/innodb_page_index.py", line 582, in _read_all_row
_data[colno],_expage[colno] = self._read_field(col)
File "/root/ibd2sql-main/ibd2sql/innodb_page_index.py", line 267, in _read_field
data = jsonob(_tdata[1:],int.from_bytes(_tdata[:1],'little')).init()
File "/root/ibd2sql-main/ibd2sql/mysql_json.py", line 201, in init
self.read_value()
File "/root/ibd2sql-main/ibd2sql/mysql_json.py", line 150, in read_value
value.append(_aa.init())
File "/root/ibd2sql-main/ibd2sql/mysql_json.py", line 193, in init
self.read_value()
File "/root/ibd2sql-main/ibd2sql/mysql_json.py", line 150, in read_value
value.append(_aa.init())
File "/root/ibd2sql-main/ibd2sql/mysql_json.py", line 201, in init
self.read_value()
File "/root/ibd2sql-main/ibd2sql/mysql_json.py", line 150, in read_value
value.append(_aa.init())
File "/root/ibd2sql-main/ibd2sql/mysql_json.py", line 193, in init
self.read_value()
File "/root/ibd2sql-main/ibd2sql/mysql_json.py", line 150, in read_value
value.append(_aa.init())
File "/root/ibd2sql-main/ibd2sql/mysql_json.py", line 192, in init
self.read_key()
File "/root/ibd2sql-main/ibd2sql/mysql_json.py", line 131, in read_key
key.append(self.bdata[x[0]:x[0]+x[1]].decode() )
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 2: invalid start byte

@ddcw
Copy link
Owner

ddcw commented Dec 13, 2024

该报错是解析JSON格式出错的, 有两种可能,

  1. 读取json二进制数据的时候就出错了.
  2. json解析的时候出错了.
    可以修改ibd2sql/innodb_page_index.py, 修改267,268行为如下内容
data = None # 设置该字段数据为空

如果其余数据能正常解析, 则说明是第二种情况
若其它数据有异常, 则说明是第一种情况
请提供下能够复现的方法, 我才能复现并修复该BUG

@Descarify
Copy link

添加后,json内容导入数据库后,直接空了,数据丢了,大佬帮看下了

@ddcw
Copy link
Owner

ddcw commented Dec 16, 2024

其它字段数据正常? 那就是第2种情况了. 可以任意发一条有问题的二进制json数据过来我看看. 目前没遇到过这种BUG(之前有个递归深度问题?)

在添加data = None的前面或者后面添加 print(_tdata)即可打印有问题的json二进制数据

@Descarify
Copy link

b'\x00\x07\x00$\x025\x00\x04\x009\x00\x05\x00>\x00\x06\x00D\x00\x06\x00J\x00\x06\x00P\x00\x07\x00W\x00\x08\x00\x0c_\x00\x00g\x00\x00|\x00\x0c\xd6\x01\x0c\xe0\x01\x0c\xf7\x01\x02 \x02sortstyleconfigtypeIdvModelcontentunitList\x071505280\x01\x00\x15\x00\x0b\x00\x05\x00\x0c\x10\x00width\x04100%\x0f\x00Z\x01m\x00\x03\x00p\x00\x04\x00t\x00\x05\x00y\x00\x06\x00\x7f\x00\x07\x00\x86\x00\x07\x00\x8d\x00\x08\x00\x95\x00\t\x00\x9e\x00\t\x00\xa7\x00\x0b\x00\xb2\x00\x0b\x00\xbd\x00\x0c\x00\xc9\x00\x0c\x00\xd5\x00\r\x00\xe2\x00\x10\x00\x0c\xf2\x00\x05\x18\x00\x0c\xfc\x00\x0c\t\x01\x02 \x01\x0c$\x01\x04\x02\x00\x04\x02\x00\x0c)\x01\x04\x01\x00\x04\x02\x00\x0cM\x01\x04\x02\x00\x04\x02\x00\x04\x02\x00tagspanlabelformIdregListtagIconrequiredchangeTagrenderKeydisplayTypeshowRegListdefaultValueshowRequiredshowClearableshowDefaultValue\tdesc-text\x0c\xe6\x96\x87\xe5\xad\x97\xe6\x8f\x8f\xe8\xbf\xb0\x16desc_text1726131910633\x00\x00\x04\x00\x04text#desc_text17261319106331726131910633\x0c\xe6\x8f\x8f\xe8\xbf\xb0\xe6\x96\x87\xe5\xad\x97\tDESC_TEXT\x16desc_text1726131910633(

3.1\xe9\x9a\x8f\xe8\xae\xbf\xe6\x9c\x9f\xe9\x97\xb4\xe5\xba\xb7\xe5\xa4\x8d\xe6\x83\x85\xe5\x86\xb5\xe8\xb7\x9f\xe8\xb8\xaa

\x00\x00\x04\x00'
b'\x02\x00\x00\x04\x00'
INSERT INTO survey-test.fm_form_item VALUES (1834470146360537089, 'CTi9RiN6', 'radio1701844190696', 'RADIO', '

随访方式

', 0, 0, 0, 1, NULL, 1, '此题为必填项目随访方式', 1048576, 24, NULL, NULL, 1764538963929927681, '1730159906595999745', '2024-9-13 13:52:20', '1765569689215361026', '2024-9-13 13:53:7');

CREATE TABLE IF NOT EXISTS survey-test.fm_form_item(
id bigint NOT NULL AUTO_INCREMENT,
form_key varchar(100) NOT NULL COMMENT '项目key',
form_item_id varchar(50) NOT NULL COMMENT '表单项Id',
type varchar(25) NOT NULL COMMENT '表单项类型',
label text NOT NULL COMMENT '表单项标题',
is_display_type bit(1) NOT NULL DEFAULT "b'0'" COMMENT '展示类型组件',
is_hide_type bit(1) NOT NULL DEFAULT "b'0'" COMMENT '隐藏类型组件',
is_special_type bit(1) NOT NULL DEFAULT "b'0'" COMMENT '特殊处理类型',
show_label bit(1) NOT NULL DEFAULT "b'0'" COMMENT '是否显示标签',
default_value varchar(1000) NULL COMMENT '表单项默认值',
required bit(1) NOT NULL COMMENT '是否必填',
placeholder varchar(255) NULL COMMENT '输入型提示文字',
sort bigint NULL DEFAULT '0' COMMENT '排序',
span int NOT NULL DEFAULT '24' COMMENT '栅格宽度',
scheme json NULL COMMENT '表表单原始JSON',
reg_list json NULL COMMENT '正则表达式',
org_id bigint NULL COMMENT '机构id',
create_by varchar(64) NULL COMMENT '创建人',
create_time datetime NULL COMMENT '创建时间',
update_by varchar(64) NULL COMMENT '更新人',
update_time datetime NULL COMMENT '更新时间',
PRIMARY KEY (id )
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT '表单项';

你好大佬,这个就是打印出来的数据和建表语句以及正常能导入的部分。

@Descarify
Copy link

获取ddl时将json转换为了blob类型导致的。重新建表,类型调整为json,然后通过表空间导入,可以了。

@ddcw
Copy link
Owner

ddcw commented Dec 17, 2024

是指ibd2sql解析DDL的时候把json转为了blob吗?

上面给出的json数据格式是混乱的, 应该被平台转义了, 你可以给出如下格式,或者上传附件

b'\x00\x07\x00$\x025\x00\x04\x009\x00\x05\x00>\x00\' ....

既然表空间导入已经可以了, 也可以忽略

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants