Creating Database Backups
Regular database backups are essential for protecting your website's data. phpMyAdmin makes it easy to export your database to an SQL file that can be stored safely and used for restoration if needed.
Exporting via phpMyAdmin
- Log in to phpMyAdmin through DirectAdmin.
- Select the database you want to export from the left sidebar.
- Click the Export tab at the top.
- Choose the export method:
- Quick - Exports the entire database with default settings. Suitable for most backups.
- Custom - Allows you to select specific tables and configure export options.
- Set the format to SQL (recommended for full backups).
- Click Go to download the export file.
Custom Export Options
When using the Custom export method, you can configure:
- Tables - Select which tables to include in the export.
- Output - Choose to save as a file (default) or display on screen.
- Compression - Select
gziporzipto compress the export file and save disk space. - Add DROP TABLE - Include
DROP TABLE IF EXISTSstatements so importing the backup will replace existing tables. - Add CREATE DATABASE - Include the database creation statement in the export.
- Data format - Choose between
INSERTstatements (standard) orINSERT IGNORE(skip duplicates).
Exporting to CSV
To export data in CSV format (useful for spreadsheets and data analysis):
- Select the specific table you want to export.
- Click the Export tab.
- Change the format from SQL to CSV.
- Configure delimiters and enclosures if needed.
- Click Go to download the CSV file.
Automated Backups via Cron
For regular automated backups, set up a cron job with the mysqldump command:
mysqldump -u username -p'password' database_name | gzip > /home/username/backups/db_$(date +%Y%m%d).sql.gz
Store backup files in a location outside your
public_html directory to prevent them from being accessible via the web. Consider also downloading copies to your local computer or an external storage service.Database backups contain all your website's data, potentially including user passwords and personal information. Treat backup files as sensitive and store them securely.