简体   繁体   中英

Migrate a SQLite3 database table to MySQL with Python without dump files

I need to migrate information that I created in SQLite3 to a MySQL database on my website. The website is on a hosted server. I have remote access to the MySQL database. I initially thought it would be easy, but I am not finding any good info on it, and everything I read seems to imply that you need to dump the SQLite3 file, convert it to a MySQL dump file using messy scripts, and then import it into the MySQL.

(example: Quick easy way to migrate SQLite3 to MySQL? )

My question: Is it not better to read it and import it straight from the script into MySQL. I haven't used MySQL at all with Python, but it would seem intuitive that it would be better to have less steps for things to be miss-read. I am also trying to save a little time by not having to understand the way that a MySQL dump file works.

If you have a script (Python if possible), tool or link that will help me out that would be great, but my main concern first of all is how to go about doing it. I can't realistically check everything (otherwise I would just do copy and paste), so I want to be sure that I am going about it the right way.

I am using Django, perhaps there is a Django specific method for it, but I haven't been able to find one.

The reason the "messy" scripts are required is that it's generally a difficult problem to solve.

If you are lucky there won't be too many schema incompatibilities between the databases.

These may help

db_dump.py
dbpickle.py
What is your favorite solution for managing database migrations in django?

Have you tried using django-admin's dumpdata and loaddata?

eg dump sqllite3 db

manage.py dumpdata

change db to mysql, recreate tables and load

manage.py loaddata mydata.json

dumpdata by default dumps json but you can set format to xml too.

Alternatively, you can just read whole sqlite3 db using python db api or sqlalchemy or django ORM and dump it to MySQL db.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM