How to import a large SQL file into MySQL

9 11 2009

As a PHP/MySQL developer I’m regularly having to download backups of my databases, and occasionally I have to import them back into MySQL.

The problem is that phpMyAdmin has a file size limit for uploading an SQL file (usually 8MB, depending on your server configuration). Some MySQL backup files are in the hundreds of MegaBytes!

The solution? If you have access to the MySQL command line prompt:

  1. Put your SQL file in a simple path (such as “C:\database.sql” on Windows, or “/home/username/database.sql” on Linux)
  2. Login to MySQL
  3. Create the database (if not already created, or if the SQL doesn’t have a “Create Database” statement)
  4. Select the database (“USE databasename;”)
  5. Run the “Source” command, like so:

SOURCE C:/database.sql
or
SOURCE /home/username/database.sql

This should import the SQL file into the database, it can take a few minutes depending on the size of the file.

I post this here just in case anyone else had trouble importing large database backups into their MySQL databases. Hope this has helped a few people!


Actions

Information

Leave a comment