1、按照 https://blog.csdn.net/wsbl52006/article/details/78677730的規程,導出sql語句
2、運行腳本:
import re
res = ""
with open('main.sql', 'r', encoding='utf-8') as f:
str = f.read()
pattern = re.compile(r"INSERT INTO .* VALUES \(\d+(?:, \w?\'[\s\S]*?\'|, [\+|\-|\.|\w]+)*\);")
results = pattern.findall(str)
for result in results:
res += result.replace('"', "") + '\n'
with open('data.sql', 'w', encoding='utf-8') as f:
f.write('SET FOREIGN_KEY_CHECKS = 0;\n')
f.write(res)
f.write('SET FOREIGN_KEY_CHECKS = 1;\n')
3、檢查是否有遺漏的數據
對於具有連續的id的數據,可採用這種方法:
select id from table a where id >= start and id <= end and not EXISTS (select id from table b where a.id + 1 = b.id)