mysqldump -u root -p company_db > company_db.sqlmysql -u root -p company_db < company_db.sqlmysql -u root -p database_name < backup.sqlmysqldump -u root -p database_name > backup.sqlIn MySQL, the terms backup/export and restore/import are often used interchangeably, but there are practical differences in meaning and purpose.
| Topic | Backup | Export |
|---|---|---|
| Purpose | Disaster recovery | Move/share data |
| Scope | Usually full database/server | Usually selected data/tables |
| Includes | Data, schema, users, routines, triggers, configs (sometimes) | Mostly schema and/or data |
| Format | SQL dump, binary backup, snapshot | Usually SQL/CSV/JSON |
| Use Case | Recover after crash | Transfer/reporting/migration |
| Tools | mysqldump, mysqlpump, Percona XtraBackup |
mysqldump, SELECT INTO OUTFILE |
| Topic | Restore | Import |
|---|---|---|
| Purpose | Recover system/database | Load external data |
| Source | Backup files | Exported files |
| Goal | Return to previous state | Insert or migrate data |
| Scope | Usually full recovery | Often partial data load |
| Examples | Recover after server failure | Import CSV into table |
Think of this as: “Save everything so we can recover later.”
mysqldump -u root -p company_db > company_db_backup.sqlLater:
mysql -u root -p company_db < company_db_backup.sqlThis restores the database after:
- server crash
- accidental deletion
- corruption
- failed deployment
Think of this as: “Move or share data.”
SELECT * FROM employees
INTO OUTFILE '/tmp/employees.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';Later import:
LOAD DATA INFILE '/tmp/employees.csv'
INTO TABLE employees
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';This is commonly used for:
- reporting
- analytics
- migrations
- Excel usage
- sharing datasets