MySQL db backup command

MySQL db backup command

Step-by-step guide for MySQL db backup command and mysql db backup cron job setup process. Find mysql db backup script and query with an example.


1. Login into Cpanel

2. Go to the “DATABASES” section on Cpanel

3. Click on the “phpMyAdmin” link under the “DATABASES” section



4. Click on MySQL Databases



5. Select the name of the Database which you want to take backup e.g. “ratecphk_aim” is the name of DB which is shown at bottom of the image



6. Replace the name of DB_Demo with the name of DB (ratecphk_aim) in the below DB Backup cron job/command


/usr/bin/mysqldump -u Current User -p'Password' DB_Demo > /home/Cpanel-username/db_`date +\%Y\%m\%d\%H\%M`.sql

/usr/bin/mysqldump -u Current User -p'Password' ratecphk_aim > /home/Cpanel-username/db_`date +\%Y\%m\%d\%H\%M`.sql



7. Under the “Current Users” section, select the name of the current user e.g. “ratecphk_default” is name of the current user as shown in the image



8. Replace the “Current User” parameter in the DB Backup command


/usr/bin/mysqldump -u Current User -p'Password' ratecphk_aim > /home/cpanel-username/db_`date +\%Y\%m\%d\%H\%M`.sql

/usr/bin/mysqldump -u ratecphk_default -p'Password' ratecphk_aim > /home/cpanel-username/db_`date +\%Y\%m\%d\%H\%M`.sql


9. Click on the “Change Password” button and reset your password if you do not know your existing DB User password.

If you want password then replace the password parameter in the DB Backup cron directly


/usr/bin/mysqldump -u ratecphk_default -p'Password' ratecphk_aim > /home/cpanel-username/db_`date +\%Y\%m\%d\%H\%M`.sql


/usr/bin/mysqldump -u ratecphk_default -p'Rghyu56&4r' ratecphk_aim > /home/cpanel-username/db_`date +\%Y\%m\%d\%H\%M`.sql

Note: There is no space between p and password in DB Backup command/cron



10. Go to the Cpanel home page

11. Under the “ADVANCED” section click on the “Cron Jobs” icon

12 Cron Jobs page opens



13. Go to “Add New Cron Job"

14. Go to “Common Settings”

15. Select the “Once Per Minutes” option if you want that Cron Job run every minute i.e. want to take DB Backup every minute

Suppose you want to task DB Backup every day then select the “Once Per Day” option


16. Mention the path of the DB Backup file on your server/Cpanel

Check “PHP Command Example” to check the path of your file

In the DB Backup command replace your file location/path

/usr/bin/mysqldump -u ratecphk_default -p'Rghyu56&4r' ratecphk_aim > /home/cpanel-username/db_`date +\%Y\%m\%d\%H\%M`.sql



17. In the command “db_`date +\%Y\%m\%d\%H\%M`.sql” parameter format is mentioned to create a DB Backup file with Time Stamp

18. /usr/bin/mysqldump -u ratecphk_default -p'Rghyu56&4r' ratecphk_aim > /home/Cpanel-username/db_`date +\%Y\%m\%d\%H\%M`.sql

19. Put the complete command with all the parameters in the “Command” text box


20. Click on the "Add New Cron Job" button

21. You successfully created DB Backup Cron Job

22. Go to file location on Cpanel to view if the DB Backup file is created

23. Thanks

Send Query