How to use crontab to backup MYSQL database regularly under Linux
Just follow the following 3 steps, everything is under your control:
Step one: Configure the backup directory code on the server:
1 2 |
|
Step two: Write backup script code:
1 2 3 4 5 6 |
|
Step 3: Change backup script permissions
1 |
|
Step 4: Use crontab to execute backup script code regularly:
1 |
|
If you back up at 21:00 every night, add the following code
1 |
|
Problems you will encounter:
1.mysqldump is the command to back up the database. If you don’t understand, just Baidu it .
2. Crontab is a command for scheduled tasks. If you don’t understand, you can visit http://www.thinkphp.cn/code/1...
3. When backing up data, you must first make sure you have set a password for root. Otherwise, Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect
will be reported when mysqldump is executed. Solution:
Log in to mysql client
1 2 3 4 5 |
|