How to Export MySQL Database
Create a reliable MySQL backup file before updates, imports, cleanup work, or server changes.
Before you start
Export the full database
The most common backup is a full export containing both table structure and data.
mysqldump -u username -p database_name > database_name_backup.sql
It creates a SQL file containing the commands needed to rebuild the database later.
Export with a dated filename
Using a dated filename makes backups easier to organize and much safer than overwriting the same file every time.
mysqldump -u username -p database_name > database_name_20260402.sql
If something goes wrong later, you can tell exactly which backup was taken before the change.
Export a single table only
If you only need one table before cleanup or testing, export just that table instead of the whole database.
mysqldump -u username -p database_name table_name > table_name_backup.sql
This is useful before updating one table, deleting duplicates, or testing risky changes in a limited area.
Export structure only
Sometimes you only need the table definitions and not the data itself.
mysqldump -u username -p --no-data database_name > database_name_structure.sql
Useful when you want the schema for documentation, migration planning, or structure comparison without exporting the actual records.
Verify that the backup file exists
Do not assume the export worked just because the command finished. Confirm the file was created properly.
ls -lh database_name_backup.sql
Make sure the file is present and the size looks reasonable for the amount of data you expected to export.
Common situations where export should come first
If you are about to remove duplicates, replace text, or modify many rows, export first.
A backup gives you a rollback point if the import creates duplicates, conflicts, or structure problems.
If the server environment changes, having a clean SQL export is one of the simplest recovery options.
An app update that changes database logic can go wrong, so exporting first is the safer move.
Common mistakes
Always verify the database name before running mysqldump.
Use dated filenames so you do not lose your earlier restore points.
Always confirm that the SQL file exists and has a believable size.
If you are about to run destructive SQL, not taking a backup first is avoidable risk.