問題:
將匯出的MySQL 轉儲SQL檔案導入SQLite3直接使用sqlite3工具存取資料庫是不成功的。如何解決這個問題?
解決方案:
以下shell 腳本可以將MySQL 轉儲檔案轉換為可以匯入SQLite3 的格式:
#!/bin/sh if [ "x" == "x" ]; then echo "Usage: <dumpname>" exit fi cat | grep -v ' KEY "' | grep -v ' UNIQUE KEY "' | grep -v ' PRIMARY KEY ' | sed '/^SET/d' | sed 's/ unsigned / /g' | sed 's/ auto_increment/ primary key autoincrement/g' | sed 's/ smallint([0-9]*) / integer /g' | sed 's/ tinyint([0-9]*) / integer /g' | sed 's/ int([0-9]*) / integer /g' | sed 's/ character set [^ ]* / /g' | sed 's/ enum([^)]*) / varchar(255) /g' | sed 's/ on update [^,]*//g' | perl -e 'local $/;$_=<>;s/,\n\)/\n\)/gs;print "begin;\n";print;print "commit;\n"' | perl -pe ' if (/^(INSERT.+?)\(/) { $a=; s/\'\''/'\'\''/g; s/\n/\n/g; s/\),\(/\);\n$a\(/g; } ' > .sql cat .sql | sqlite3 .db > .err ERRORS=`cat .err | wc -l` if [ $ERRORS == 0 ]; then echo "Conversion completed without error. Output file: .db" rm .sql rm .err rm tmp else echo "There were errors during conversion. Please review .err and .sql for details." fi
說明:
以上是如何將 MySQL 轉儲檔案轉換為 SQLite 可匯入格式?的詳細內容。更多資訊請關注PHP中文網其他相關文章!