Importing large databases sucks. It can take anywhere from as short as 10 min to a few hours. Worse is when it fails mid-import. So here is a faster & more reliable way to import.
Disclaimer:
- This tutorial is only for macOS users. If you’re on windows, good luck.
- This script can import a 30gb database in under 40min, tested on Macbook M1.
Prerequisites:
- Must use MAMP.
- Must have Homebrew installed.
Install these using Brew
- brew install pv
- brew install pigz
What it does, in steps:
- 3 arguments: gzipped SQL file, database name, MySQL user (defaults to root)
- Disables safety temporarily. Turns off foreign key checks, unique checks, binary logging.
- Cranks up InnoDB settings. Bigger buffer pool, less aggressive flushing to disk.
- Decompresses & imports. Uses the faster parallel gunzip (pigz) if available, otherwise falls back to regular gunzip. The pv command shows progress.
- Restores safety when done.
Placing the fast import script
Download the file from my GitLab
Make sure its placed inside this folder
/users/<your_username_here>
Update the permission of the file
chmod +x ~/fast_mysql_import.sh
Update zshrc, include MAMP path
echo 'export PATH="/Applications/MAMP/Library/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Run the script
./fast_mysql_import.sh ~/Desktop/smaplivedb-20260303-0630.sql.gz smap030326 root
Credits to Danish for creating the script.
Comments
Post a Comment