Mysql – How to create a MySQL database based on a SQLite schema

MySQLsqlite

I have MySQL on my server and different SQLite databases on a client. I'm trying to find a way to create the same databases on the server.

Since a SQLite schema is actually a CREATE query, one way would be to write a script that extracts every critical part from the create query and converts them into a corresponding MySQL query, finally concatenate them all.

This seems quite a complex and hard-to-cover-all-situations method. I am wondering if there is any alternatives?

Best Answer

The three main things to change are:

  • Change AUTOINCREMENT to AUTO_INCREMENT
  • Replace double-quotes around database, table and variable names with backticks
  • Delete any lines with “sqlite_sequence” in them

You should then be able to run the SQL file in MySQL. If you encounter any errors, the fix should be apparent from the error message shown.