将mysql中的数据转到sqlite
2014-09-12 22:17:45 阿炯

本站赞助商链接,请多关照。 如果mysql表中的字段值较为简单,可以使用select ... into outfile这种方式将这些记录存为带格式的csv文件,然后用导入文件内容的方式插入到sqlite 表中。

但很多情况下表中的字段值并不简单,因此上面的方法大都不能操作成功。大都会报字段数量不对等信息:
Error: freeoa.csv line 2: expected x columns of data but found y

To import from an SQL file use the following:
sqlite> .read <filename>

To import from a CSV file you will need to specify the file type and destination table:
sqlite> .mode csv <table>
sqlite> .import <filename> <table>

另在github上有一个shell脚本,可以从mysql中将dump出来的数据生成sqlite可以执行的语句。
地址:https://gist.github.com/esperlu/943776#file-mysql2sqlite-sh

这是目前工作的最好的脚本了,转换后可轻松地将mysql中的数据导入到sqlite中。