2012-12-04 3 views
0

다음 스크립트를 사용하여 mysqldump 파일을 Sqlite 3 호환 파일로 변환하려고합니다.mysql 덤프를 sqlite 호환 파일로 변환하는 중 오류가 발생했습니다.

DROP TABLE IF EXISTS "acos"; 
/*!40101 SET @saved_cs_client  = @@character_set_client */; 
/*!40101 SET character_set_client = utf8 */; 
CREATE TABLE "acos" (
    "id" int(10) NOT NULL, 
"parent_id" int(10) DEFAULT NULL, 
    "model" varchar(255) DEFAULT NULL, 
    "foreign_key" int(10) DEFAULT NULL, 
    "alias" varchar(255) DEFAULT NULL, 
    "lft" int(10) DEFAULT NULL, 
    "rght" int(10) DEFAULT NULL, 
    PRIMARY KEY ("id"), 
    FULLTEXT KEY "alias" ("alias") 
); 

오류 : anees - 바탕 화면 @

'/home/anees/TestProjects/mysqltosqlite/sqltests/mysql-to-sqlite.sh'  '/home/anees/TestProjects/mysqltosqlite/sqltests/mydb.sql' 
Error: near line 26: near ")": syntax error 
Error: near line 41: near "LOCK": syntax error 
Error: near line 43: no such table: acos 
Error: near line 44: no such table: acos 
Error: near line 45: no such table: acos 
Error: near line 46: no such table: acos 
Error: near line 48: near "UNLOCK": syntax error 
Conversion completed without error. Output file: /home/anees/TestProjects/mysqltosqlite/sqltests/mydb.sql.db 

anees : ~/TestProjects/mysqltosqlite/I는 다음과 덤프 파일을 변환 할 때

#!/bin/bash 
if [ "x$1" == "x" ]; then 
echo "Usage: $0 <dumpname>" 
exit 
fi 

cat $1 | 
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' | 
sed 's/\\r\\n/\\n/g' | 
sed 's/\\"/"/g' | 
sed 's/ "id" bigint(20) NOT NULL/ "id" integer primary key autoincrement/g' | 
perl -e 'local $/;$_=<>;s/,\n\)/\n\)/gs;print "begin;\n";print;print "commit;\n"' | 
perl -pe ' 
if (/^(INSERT.+?)\(/) { 
$a=$1; 
s/\\'\''/'\'\''/g; 
s/\\n/\n/g; 
s/\),\(/\);\n$a\(/g; 
} 
' > $1.sql 
cat $1.sql | sqlite3 $1.db > $1.err 
ERRORS=`cat $1.err | wc -l` 
if [ $ERRORS == 0 ]; then 
echo "Conversion completed without error. Output file: $1.db" 
else 
echo "There were errors during conversion. Please review $1.err and $1.sql for details." 
fi 

는 나는 다음과 같은 오류가 발생합니다 sqltests $

답변

1

FULLTEXT KEY을 제거하십시오. SQLite에서 전체 텍스트 검색은 differently으로 작동합니다.

덤프에 다른 오류가 있지만 코드를 표시하지 않았습니다. 어쨌든 LOCK/UNLOCK 명령을 제거하면됩니다.

1

필드 이름과 마찬가지로 테이블 이름에 역순으로 쉼표를 제거하십시오.

DROP TABLE IF EXISTS acos; 
/*!40101 SET @saved_cs_client  = @@character_set_client */; 
/*!40101 SET character_set_client = utf8 */; 
CREATE TABLE acos (
+0

이제'anees @ anees-desktop : ~/TestProjects/mysqltosqlite/sqltests $ '/home/anees/TestProjects/mysqltosqlite/sqltests/mysql-to-sqlite.sh' '/ home/anees/TestProjects/mysqltosqlite가 표시됩니다. /sqltests/mydb.sql ' 오류 : 근처 라인 26 : "별칭"근처에서 : 구문 오류 오류 : 라인 42 근처 : "LOCK"근처 : 구문 오류 오류 : 라인 근처 44 : 해당 테이블 없음 : acos 오류 : acos 오류 : 근처 46 : 해당 테이블 없음 : acos 오류 : 근처 47 : 해당 테이블 없음 : acos 오류 : 근처 49 : "UNLOCK"근처 : 구문 오류 ' – user1400538

관련 문제