Cron jobs allow you to automate certain commands or scripts on your site. You can set a command or script to run at a specific time every day, week, etc. For example, you could set a cron job toÂ backupÂ your MySQL Â database everyday so that you can recover your data if anything happen to your data like data missing and etc.
Here I want to share with you’ll on how to backup MySQL database and email the results automatically using Cron Jobs and cPanel (Shared Hosting). To doing this, follow the following step:
This method apply to XAMPP and phpMyAdmin.
1. Backup database from the source. Normally the database will using name : localhost.sql
2. After backup, transfer to any folder in the MySQL server that you want to restore, it’s better put into /root
3. Delete database using phpMyadmin if the database exist
3. Then execute commmand: mysql -u root -p < localhost.sql
4. If using XAMPP, it may show error message: -bash: -bash:: command not found
5. If you found this error, try find using this command: find /opt/lampp -name mysql
6. You should found this result: /opt/lampp/bin/mysql
7. Now create shortcut to execution path (/bin)
8. Using this command to create shortcut: ln -s /opt/lampp/bin/mysql /bin/mysql
9. After that, try again to execute: mysql -u root -p < localhost.sql
10. If everything OK, you should prompted the phpMyadmin password
11. Enter password and it will restore the database
12. Double check again the restored database