_ _ _ _
__| | |__ | |_ ___ ___ | |___
/ _` | '_ \| __/ _ \ / _ \| / __|
| (_| | |_) | || (_) | (_) | \__ \
\__,_|_.__/ \__\___/ \___/|_|___/
MySQL Database Utilities
By Dilan D Chandrajith - The Perfect Developer
Bash scripts for dumping and restoring MySQL databases with progress tracking and resume support.
- Partial dumps: Fetch only the latest N records from large tables
- Full table dumps: Specify tables that need complete data
- Resume support: Interrupted dumps can be resumed from where they left off
- Progress display: Visual progress bar using
pv - Collation compatibility: Automatically converts MySQL 8.0+ collations for older versions
mysqlandmysqldumpclientspv(pipe viewer) for progress displaysedfor collation conversion
Install dependencies:
# Debian/Ubuntu
sudo apt install mysql-client pv
# macOS
brew install mysql-client pvcurl -fsSL https://raw.githubusercontent.com/the-perfect-developer/perfect-db-tools/main/get.sh | sudo bashThis installs dbtools to /opt/dbtools and creates a symlink in /usr/local/bin.
To uninstall:
sudo rm -rf /opt/dbtools /usr/local/bin/dbtoolsClone the repository and install manually:
git clone https://github.com/the-perfect-developer/perfect-db-tools.git
cd the-perfect-dbtools
sudo ./install.sh --installTo uninstall:
sudo ./install.sh --uninstallUse the unified dbtools.sh command:
./dbtools.sh <command> [options]
Commands:
dump Dump a MySQL database
restore Restore a MySQL database from a SQL file
update Update dbtools to the latest versionExamples:
# Dump a database
dbtools dump -u root -d mydb
# Restore a database
dbtools restore -u root -d mydb -f backup.sql
# Update to latest version
dbtools update
# Get help
./dbtools.sh --help
./dbtools.sh dump --helpDump a MySQL database with optional table filtering.
./dbtools.sh dump [OPTIONS]Options:
| Option | Description | Default |
|---|---|---|
-u, --user |
Database username | (required) |
-p, --password |
Database password | (optional) |
-h, --host |
Database host | localhost |
-P, --port |
Database port | 3306 |
-d, --database |
Database name | (required) |
-o, --output |
Output SQL file | <database>.sql |
-l, --limit |
Max records per table for non-full tables | none (dumps all) |
-t, --tables |
Comma-separated list of tables to dump fully | (none) |
--help |
Show help message |
Examples:
# Basic dump with default 500 record limit
./dbtools.sh dump -u root -d mydb
# Dump with custom record limit
./dbtools.sh dump -u root -d mydb --limit=1000
# Dump with specific tables to be dumped fully
./dbtools.sh dump -u root -d mydb -t users,orders,products
# Full example with all options
./dbtools.sh dump -u root -p secret -h 192.168.1.100 -P 3306 -d mydb -o backup.sql -l 2000 -t users,ordersRestore a MySQL database from a SQL file.
./dbtools.sh restore [OPTIONS]Options:
| Option | Description | Default |
|---|---|---|
-u, --user |
Database username | (required) |
-p, --password |
Database password | (optional) |
-h, --host |
Database host | localhost |
-P, --port |
Database port | 3306 |
-d, --database |
Database name | (required) |
-f, --file |
SQL file to restore | (required) |
--help |
Show help message |
Examples:
# Basic restore
./dbtools.sh restore -u root -d mydb -f backup.sql
# Restore to remote server
./dbtools.sh restore -u root -p secret -h 192.168.1.100 -P 3306 -d mydb -f backup.sql- Fetches list of all tables in the database
- For each table:
- If in
--tableslist: dumps complete table with all data - Otherwise: dumps table structure + latest N records (based on
--limit)
- If in
- Progress is tracked in a
.progressfile for resume support - If interrupted, rerun the same command to resume
- Creates the database if it doesn't exist
- Converts MySQL 8.0+ collations to compatible ones for older versions
- Imports the SQL file with progress display
After cloning, install git hooks with one command:
./install-hooks.shHooks automatically run ShellCheck, syntax validation, conventional commit message linting, and the full test suite. See .githooks/README.md for details.
To check hook status:
./install-hooks.sh --checkDilan D Chandrajith - The Perfect Developer
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Contributions are welcome! Please read CONTRIBUTING.md for setup instructions, coding conventions, and pull request expectations.