在AWS RDS中将sqlite3从Django迁移到mysql时始终报告语法错误

在AWS RDS中将sqlite3从Django迁移到mysql时始终报告语法错误,mysql,django,amazon-web-services,sqlite,Mysql,Django,Amazon Web Services,Sqlite,我正在AWS RDS中将django sqlite3迁移到mysql(我对mysql非常陌生)。我所做的是: (1) 首先,我通过sudosqlite3db.sqlite3.dump>/home/ubuntu/temp.sql (2) 然后我尝试了sudomysql-h MYRDSHOSTNAME-u MYUSERNAME-p3306-pmydb

我正在AWS RDS中将django sqlite3迁移到mysql(我对mysql非常陌生)。我所做的是:

(1) 首先,我通过
sudosqlite3db.sqlite3.dump>/home/ubuntu/temp.sql

(2) 然后我尝试了
sudomysql-h MYRDSHOSTNAME-u MYUSERNAME-p3306-pmydb

(3) 输入密码后,我得到了这个

您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以了解第1行“PRAGMA foreign_keys=OFF”附近使用的正确语法

我尝试删除temp.sql中的第一行,但随后发生了相同的错误,它仍然指向第1行

我还检查了RDS中的mydb,以确保它确实存在。它就在那里(当然是空的)。

RDS上的MySQL引擎版本为5.6.22,django电脑上的MySQL引擎版本为5.6.19


有没有什么我忽略了或做错了?非常感谢你们

SQLite3和MySQL的语法略有不同。看看这个问题:啊哈!谢谢我现在正在玩翻译脚本。sqlite中有一个独特的(xxx,yyy)。我应该在MySQL中删除这个吗?据说在MySQL中没有使用UNIQUE。
#!/usr/bin/env python

import re
import fileinput

def this_line_is_useless(line):
    useless_es = [
        'BEGIN TRANSACTION',
        'COMMIT',
        'sqlite_sequence',
        'CREATE UNIQUE INDEX',
        'PRAGMA foreign_keys=OFF'
        ]
    for useless in useless_es:
        if re.search(useless, line):
                return True

def has_primary_key(line):
    return bool(re.search(r'PRIMARY KEY', line))

searching_for_end = False
for line in fileinput.input():
    if this_line_is_useless(line): continue

    # this line was necessary because ''); was getting
    # converted (inappropriately) to \');
    if re.match(r".*, ''\);", line):
        line = re.sub(r"''\);", r'``);', line)

    if re.match(r'^CREATE TABLE.*', line):
        searching_for_end = True

    m = re.search('CREATE TABLE "?([A-Za-z_]*)"?(.*)', line)
    if m:
        name, sub = m.groups()
        line = "DROP TABLE IF EXISTS %(name)s;\nCREATE TABLE IF NOT EXISTS %(nam                                                                             e)s%(sub)s\n"
        line = line % dict(name=name, sub=sub)
    else:
        m = re.search('INSERT INTO "([A-Za-z_]*)"(.*)', line)
        if m:
                line = 'INSERT INTO %s%s\n' % m.groups()
                line = line.replace('"', r'\"')
                line = line.replace('"', "'")
    line = line.replace('AUTOINCREMENT','AUTO_INCREMENT')
    #line = line.replace('UNIQUE ','')
    line = line.replace('"','')
    line = re.sub(r"(?<!')'t'(?=.)", r"1", line)
    line = re.sub(r"(?<!')'f'(?=.)", r"0", line)

    # Add auto_increment if it's not there since sqlite auto_increments ALL
    # primary keys
    if searching_for_end:
        if re.search(r"integer(?:\s+\w+)*\s*PRIMARY KEY(?:\s+\w+)*\s*,", line):
            line = line.replace("PRIMARY KEY", "PRIMARY KEY AUTO_INCREMENT")
        # replace " and ' with ` because mysql doesn't like quotes in CREATE com                                                                             mands

    # And now we convert it back (see above)
    if re.match(r".*, ``\);", line):
        line = re.sub(r'``\);', r"'');", line)

    if searching_for_end and re.match(r'.*\);', line):
        searching_for_end = False

    if re.match(r"CREATE INDEX", line):
        line = re.sub('"', '`', line)

    print line,
sqlite3 sample.db .dump | python dump_for_mysql.py > dump.sql