Splitting up Unweildy Database Dumps/Exports

Submitted by ethan on

I recently found myself in possession of a huge (~1.5GB) MySQL dump that I needed to restore after a system reinstall. When a text file gets this large, it is very difficult to edit or even view, as text editors simply can't handle the size. Fortunately, I figured out a simple way of separating the single file into separate databases that could be viewed or imported individually. It works because a typical database dump first creates the database, then the tables, then inserts the data into those tables. It does this sequentially, for one database at a time. My solution simply uses the csplit (Standard in GNU/Linux, OS X) and a regular expression searching for lines starting with "CREATE DATABASE".

 csplit -k -f db -n 2 dump.sql '/^CREATE DATABASE.*$/' {50}

The arguments are well documented, but the important one is the regular expression, '/^CREATE DATABASE.*$/'. You'll see a number of files titled db00, db01, etc. which contain the SQL queries required to restore one complete database.

You can then use phpMyAdmin or the mysql command-line to individually import each database. If these prove unsuccessful, a php script named BigDump might be of use.

  • Cross-platform software
  • Computing
  • PHP programming language
  • Databases
  • Data management
  • SQL
  • PhpMyAdmin
  • Database management systems
  • MySQL
  • Database dump
  • Database
  • Technology Internet
  • Mac OS X
  • MySQL
  • MySQL AB
  • GNU/Linux
  • php
  • php
  • SQL
  • Linux

Section: 

Topic: 

Add new comment