Get the App
SLTechnology News&Howtos  ›  Development  › 

Shell script sharing for scheduled backup of mysql under CentOS

Shulou Source: shulou.com Published: 2022-06-03 13:09:34 11月14日 Update

This article mainly explains "Shell script sharing for regular backup of mysql under CentOS". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "Shell script sharing for regular backup of mysql under CentOS".

1. Backup statement

The code is as follows:

# / usr/local/mysql/bin/mysqldump-utest-ptest test--socket=/tmp/mysql.3306.sock > / usr/local/mysql_backup/3306/test- `date +% Y% m% d`.sql.gz

Statement description:

/ usr/local/mysql/bin/mysqldump:MySql installation directory

-utest: divided into two parts, one is-u and the other is test;, where-u represents the user name and test represents the current user name

-ptest: divided into two parts, one is-u and the other is test;, where-u represents the password and test represents the current password

-- socket: which port is backed up, and check which port under / tmp matches

Test: which database to back up

>: which folder is the backup in, and named after the database name-current date

2. Write the statement into a script

3. Edit / etc/crontab

The code is as follows:

# vim / etc/crontab

4. Add below

The code is as follows:

00 3 * root / home/mysql/3306/backup

Note: backup is the script you just wrote

Indicates that a backup is performed at 3 o'clock every day

5. Restart crontab

The code is as follows:

# / etc/rc.d/init.d/crond restart

Thank you for reading, the above is the content of "Shell script sharing for regular mysql backup under CentOS". After the study of this article, I believe you have a deeper understanding of the problem of Shell script sharing for regular mysql backup under CentOS, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Backups scripts code statements learning content passwords data databases users user names namely ideas situations files folders articles dates more directories Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Tech Info MySQL MariaDB vpn