Mysql dump by query
Get a tailored MySQL dump by appending --where to the mysqldump command. To export user records made in 2023:
mysqldump -u user -p database user --where="created_at >= '2023-01-01'" > user_dump2023.sql
Modify user, database, and the date to fit your needs. To export results of a specific SQL query:
mysql -u user -p -e "SELECT * FROM myTable WHERE condition" database > myQueryResult.txt
Command mastery for selective row dumps
Dumping specific rows
mysqldump is handy when backing up part of a table. The --where option exports rows fitting a condition:
// "// Just like fishing. Don't need the whole sea, just a few specific fish!" 😏
Exclude table structure
For dumps that contain only data use the --no-create-info flag:
// "// Who needs a blueprint when we're moving furniture, am I right?" 😄
Connection essentials
Don't forget to state host, user, and password:
Limit amount of exported records
Limit the number of rows using --where for data samples:
// "// Slow and steady wins the race, right? Yeah, not in SQL!" 😂
Diving into exporting options and considerations
Emulating phpMyAdmin
Crave for a GUI-like command line? mysqldump can simulate phpMyAdmin's export functionality:
// "// Now who said command lines can't be user-friendly? 🎉"
Exporting data to CSV
Need the data in a spreadsheet format? Use SELECT INTO OUTFILE:
// "// Dear Excel nerds, we didn't forget about you!" 🤓
Unraveling the command differences
mysqldump is designed to preserve full database integrity, while SELECT outputs focus on data substance.
Dealing with enormous data
For large databases, consider mydumper and myloader, which support multi-threading for fast data processing and restoration.
// "// Size really does matter... in databases" 📏
Understand backups for diverse needs
Whole database backup
Keep it simple for complete database backups:
Data migration
Migrating between servers? Try this:
// "// Who needs a moving truck when you have pipes?" 😎
Secure your data
Working with sensitive data? Run your SQL dumps through gzip to encrypt and compress:
Was this article helpful?