Convert SQLite to MySQL.

Is it possible to convert SQLite to MySQL "as is"?

Probably the quick and easiest way to convert SQLite to MySQL includes two general steps:

  1. Export SQLite database to dump file using SQLite .dump command.
    sqlite3 sample.db .dump > dump.sql
  2. You can then (in theory) import SQLite dump into the MySQL database.
    mysql -p -u root -h 127.0.0.1 test < dump.sql

"In theory" means that solution wouldn't work as there are a few differences in grammars between MySQL and SQLite.

There are just some differences between SQLite and MySQL syntax

SQLite MySQL
            BEGIN TRANSACTION;

            ...
            
            COMMIT;
            
            BEGIN;
            
            ...
            
            COMMIT;
            
AUTOINCREMENT AUTO_INCREMENT
TEXT varchars
double quotes (" ") backticks (` `)

These differences clearly answer NO to the question asked in the title of this section.

Write a Perl/ Python script to migrate SQLite to MySQL.

Another possible way is to write a free Perl or Python script for converting SQLite to MySQL.

In the most trivial way python code may looks like:

objects = ModelObject.objects.using('sqlite').all()

for obj in objects:
    obj.save(using='mysql')
    

We are a little bit closer at this point, but it is still just a half to complete a data migration job. Writing a simple python script is most likely not enough. SQLite to MySQL migration is a more complex job than just dumping data from a source SQLite and then importing this SQLite dump into the MySQL database.

To address the challenges of data migration between SQLite and MySQL, we offer DBConvert and DBSync software.

Four reasons for using DBConvert to convert data from SQLite to MySQL?

  1. DBConvert tools combine an intuitive interface with powerful and useful features to transfer SQLite files to local or remotely hosted MySQL servers quickly. Choose the whole source database or select just several database objects to be converted to the target DB in the Interactive GUI interface. You don't need to know how to write scripts to work with DBConvert migration tools.
  2. After making a copy of your source database to target DB, keep your databases in Sync with Update, Insert, and Drop synchronization features.
  3. You can configure a DBSync windows application to perform bidirectional replication between SQLite and MySQL (where two different databases simultaneously replicate changes from each other).
  4. In any combination, data migrations between the following databases are possible
    • SQLite,
    • MySQL, MariaDB, Percona on-premises,
    • Windows Azure SQL Databases for MySQL/ Azure SQL Data Warehouse
    • AWS RDS | Aurora,
    • SQL Cloud for MySQL
    • Please refer to the list of available conversion and sync directions in product info cards on the right.
 DBConvert for SQLite & MySQL

Migration directions:

  • SQLite → MySQL, MariaDB, Percona
  • MySQL, MariaDB, Percona → SQLite
  • SQLite ↔ Amazon RDS | Aurora
  • SQLite ↔ Google Cloud SQL for MySQL
  • SQLite ↔ Azure Database for MySQL
  • ☑ Migrate to MySQL Dump, PHP Script

Version: 1.8.5

Release Date: Feb. 14, 2019

 DBSync for SQLite & MySQL

Sync directions:

  • SQLite ↔ MySQL ↔ MariaDB
  • SQLite ↔ Amazon RDS | Aurora
  • SQLite ↔ Google Cloud SQL for MySQL
  • SQLite ↔ Azure Database for MySQL

Version: 1.5.7

Release Date: Feb. 13, 2019

Try All-in-one DB migration and Sync software.

DBConvert Studio

 Version: 1.8

Release Date: Aug. 4, 2020

Supported databases:

  • SQL Server
  • MySQL
  • Oracle
  • PostgreSQL
  • Access
  • FoxPro
  • SQLite
  • Firebird
  • Excel
  • IBM DB2
  • Azure SQL
  • Amazon RDS
  • Amazon Aurora
  • Heroku Postgres
  • Google Cloud

Using SQLite to MySQL conversion and synchronization tools.

When you start DBConvert or DBSync application in GUI mode it guides you through several steps to set up the database migration or synchronization:

1. Connect to SQLite source database.

If a source database requires you to log in, you can specify a user name/ password and host/ port parameters.

Connect to SQLite source database from DBConvert

2. Connect to MySQL destination database.

Specifying parameters for destination database looks like the same as for source. Usually, it consists of defining connection settings and username/password pairs.

Connect to MySQL target database from DBConvert

NOTE #1: Every DBConvert or DBSync tool has two different databases in its name. That means any specified database from a pair can be set up as a source or destination. Besides, the same type of database may be set up both as a source or destination.

As an example, here is the list of possible migration directions with on-premises databases:

  • SQLite to MySQL
  • MySQL to SQLite
  • SQLite to SQLite
  • MySQL to MySQL

NOTE #2: Don't be confused by the fact that connections to cloud databases like Amazon RDS, Microsoft Azure SQL, Google Cloud, and Heroku are not explicitly specified in the configuration of a source or destination in the DBConvert / DBSync interface. To connect to Cloud database instances, use the same settings as you do for traditional on-premises databases.

NOTE #3: Your connections to source and target databases stay active until you close DBConvert/ DBSync application or reopen new connections on "source" and "destination" steps.

Read more about the specific source/ destination configurations for different databases.

3. Custoimzation and configuration.

At the next step, you can specify precisely which tables, fields, indices, views you want to transfer to the MySQL destination database. Just check/ uncheck the box in front of each database object you want to convert.

Customize general database/ tables settings. Or set up a particular table , field, index individually when migrating data from SQLite to MySQL.

Check out our articles about Custoimzation and configuration. for detailed information.

The screenshot below sums up general features available in DBConvert software solutions.

4. Detection of potential database migration issues. Errors and Warnings

The database typically constrains certain relations on the data that cannot be violated. On the customization step, a smart error checker verifies all possible Data integrity and Referential integrity issues and highlights them, if any, before performing a migration.

DBConvert software to default tries to automatically map database types from the source SQLite database to the closest equivalent of the target MySQL database types. But you can manually change data types for the whole database globally with "Global mapping" or individually for each field.

Check out Smart error checker. Errors and Warnings for more information.

5. Execution. The final stage of data migration from SQLite to MySQL

Once you configure source and destination databases for migration in the previous steps, you can start the actual conversion or synchronization process.

Click the "Commit" button to start conversion. Also, here, you can monitor the migtation/ synchronization process.

Optionally save connection settings and configuration parameters into the session file to schedule the launching of sync or migration jobs regularly.

Execution step of DBConvert products

Read more about execution stage available options.

Command line mode

Previously saved sessions can be passed as parameters to Command-Line DBConvert Client. A session keeps SQLite source and MySQL target database connection settings with other specified options.

Example: C:\Program Files\DBConvert\sqlite2mysqlPro\sqlite2mysqlPro_Cons.exe /Session:"Session_Name"

NOTE: First, you have to run the software in GUI mode to create a session file with initial parameters.

Built-in scheduler.

Our applications come with a built-in scheduler to run database migration and sync jobs at specified times. Just set the scheduled date and time to execute job sessions automatically.

DBConvert screenshot

Highlights

Requirements

  • Necessary privileges to write into database on the target MySQL server (this requirement is optional as there is an option to overcome the restrictions using dump file or PHP Script)
  • Necessary privileges to write into network shared folder (LAN or VPN) where destination database SQLite resides