2 ways to back up your MySQL databases using cron jobs in your LINUX cpanel 2 ways to back up your MySQL databases using cron jobs in your LINUX cpanel
backups Cpanel

2 ways to back up your MySQL databases using cron jobs in your LINUX cpanel

Always make sure your database is secured and has backup scheduling this will help you in the future when your website suddenly failed to functions. By following this procedure you will gain benefits. Do it now!

Example:

www.mywebsitename.com

mywebsite_wp990.sql

Create a folder backup to execute the backup

LINUX command:

/mywebsite/bin/mysite -u dbmywebsite_a2wp959 -p ‘()*()*())!@#’mywebsite_a2wp959> /path/sql_backups

 

METHOD 2:

Create a file in your directory: Remember to use the file not folder name this will cause error if you are in the wrong command line.

.my.cnf

[client]
username = myecommerce_wp343
password =” 0980@#@#89899OPIP!@”
host = localhost

mysqldump dbheadstar_wp691 > /path/sql_backups >/dev/null 2>&1

 

 

If you forget the password of your database then change new password. Otherwise you cannot connect to your database.

METHOD 2: follow these steps:

Create a file named .my.cnf in your /home/username directory, replacing username with your account username.
Make sure you include the leading . in the filename.

Copy and paste the following text into the .my.cnf file. Replace dbusername with the database user and replace dbpassword with the database user’s password:

[client]
user = dbusername
password = “dbpassword”
host = localhost
Create a cron job that runs the following command. Replace dbname with the name of the database to back up, and replace path with the path to store the backup file. This example uses backup.sql for the backup’s filename, but you can use any filename you want:

mysqldump dbname > /path/backup.sql

 

Note:

Warning: You need to have a good knowledge of Linux commands before you can use cron jobs effectively. Check your script with your hosting administrator before adding a cron job.

 

source:

https://www.a2hosting.com/kb/developer-corner/mysql/mysql-database-backups-using-cron-jobs