MySQL转储到SQLite导入
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL转储到SQLite导入相关的知识,希望对你有一定的参考价值。
import re, fileinput def main(): for line in fileinput.input(): process = False for nope in ('BEGIN TRANSACTION','COMMIT', 'sqlite_sequence','CREATE UNIQUE INDEX'): if nope in line: break else: process = True if not process: continue m = re.search('CREATE TABLE "([a-z_]*)"(.*)', line) if m: name, sub = m.groups() line = '''DROP TABLE IF EXISTS %(name)s; CREATE TABLE IF NOT EXISTS %(name)s%(sub)s ''' line = line % dict(name=name, sub=sub) else: m = re.search('INSERT INTO "([a-z_]*)"(.*)', line) if m: line = 'INSERT INTO %s%s ' % m.groups() line = line.replace('"', r'"') line = line.replace('"', "'") line = re.sub(r"([^'])'t'(.)", "1THIS_IS_TRUE2", line) line = line.replace('THIS_IS_TRUE', '1') line = re.sub(r"([^'])'f'(.)", "1THIS_IS_FALSE2", line) line = line.replace('THIS_IS_FALSE', '0') print line, main()
以上是关于MySQL转储到SQLite导入的主要内容,如果未能解决你的问题,请参考以下文章
如何将加载 .sql 或 .csv 文件导入 SQLite?