MySql Export / Import Large Database
Exporting and importing large MySQL databases through tools like MySQL Workbench or phpMyAdmin can fail when dealing with particularly large tables. A 250+ MB database with several heavy tables will often time out or produce incomplete dumps through the standard single-file export.
There is a straightforward workaround using MySQL Workbench's dump project folder format combined with a simple terminal command to consolidate the files before import.
The Problem
Exporting to a single self-contained SQL file fails when the database contains tables with millions of rows. The export process runs out of memory, times out, or produces a file that cannot be cleanly imported due to size constraints in phpMyAdmin or similar tools.
Step 1: Export as a Dump Project Folder
In MySQL Workbench, instead of exporting to a single self-contained SQL file, select the Dump Project Folder option. This exports each table as a separate SQL file.
For a database with 180 tables, you will end up with approximately 180 individual .sql files — one per table. Each file is a manageable size even when the combined total is hundreds of megabytes.
Step 2: Concatenate All Files into One
Navigate to the folder containing the exported SQL files and run:
cat *.sql > single_file.sql
This merges all individual table files into a single SQL file in the same directory. The cat command concatenates them in filesystem order, which preserves the correct execution sequence for tables without foreign key dependencies.
If your database uses foreign keys, you may need to order the files manually or wrap the import with SET FOREIGN_KEY_CHECKS=0; at the top of the combined file.
Step 3: Import via Terminal
Import the consolidated file using the MySQL command-line client. For a MAMP installation:
/Applications/MAMP/Library/bin/mysql -u DB_USER -p DB_NAME < single_file.sql
For a standard Linux MySQL installation:
mysql -u DB_USER -p DB_NAME < single_file.sql
You will be prompted for the password. The import runs entirely in the terminal, bypassing the size limitations of browser-based tools.
Prerequisites
- Terminal access to the machine running MySQL
- The MySQL command-line client installed (included with most MySQL installations)
- The target database already created on the destination server
Conclusion
When GUI tools fail on large databases, splitting the export into per-table files and concatenating them before a terminal import is a reliable approach. It sidesteps the memory and timeout constraints of browser-based tools while keeping the process simple — no specialized scripts or third-party utilities required.