Get the App
SLTechnology News&Howtos  ›  Database  › 

How to realize the backup of mysql in different databases

Shulou Source: shulou.com Published: 2022-05-31 13:58:23 09月30日 Update

This article mainly explains "how to achieve mysql sub-library backup", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to achieve mysql sub-library backup" bar!

In fact, sub-library backup is to execute a backup statement (mysqldump) to back up a library. If there are multiple libraries in the database, perform multiple backup statements for backing up a single library. Note that each library can use the corresponding backup library as the library name, ending with. Sql.

I wrote the following script for sub-library backup:

[root@Mysql01 mysqldumpbak] # cat / usr/local/script/mysqldump.sh

#! / bin/bash

Cd / opt/db_backup/db_backup/mysql_bak/

Rq= `date +% F`

Mkdir $rq

Cd $rq

Echo 'start backup time:' `date` > > backup.log

# since this script backup uses gizp compressed backup, it can be decompressed with gzip xxx.sql.gz when pressurized

Mysql-udbbackup_user-proomxxxxx'-e "show databases" | grep-Evi "database | perfor | infor" | sed-r's / ^ ([a Rizz]. * $) / mysqldump-udbbackup_user-proomxxxx'-routines-triggers-events-single-transaction-master-data=2-log-error=backup.err-B\ 1 | gzip >\ 1.sql.gzqpash g' | bash

Echo 'end backup time:' `date` > > backup.log

Test:

[root@Mysql01 mysqldumpbak] # sh / usr/local/script/mysqldump.sh

After the script is executed, the following sql statement is produced and the following sql is automatically executed for backup

/ home/mysql/mysql/bin/mysqldump-udbbackup_user-pxx-- routines-- triggers-- events-- single-transaction-- master-data=2-- log-error=backup.err-B app | gzip > app.sql.gz

/ home/mysql/mysql/bin/mysqldump-udbbackup_user-pxx-- routines-- triggers-- events-- single-transaction-- master-data=2-- log-error=backup.err-B ad | gzip > auod.sql.gz

/ home/mysql/mysql/bin/mysqldump-udbbackup_user-pxx-- routines-- triggers-- events-- single-transaction-- master-data=2-- log-error=backup.err-B ad_moerben | gzip > auod_moerben.sql.gz

/ home/mysql/mysql/bin/mysqldump-udbbackup_user-pxx-- routines-- triggers-- events-- single-transaction-- master-data=2-- log-error=backup.err-B ccms | gzip > cz_bj_cms.sql.gz

/ home/mysql/mysql/bin/mysqldump-udbbackup_user-pxx-- routines-- triggers-- events-- single-transaction-- master-data=2-- log-error=backup.err-B cs | gzip > cz_bj_oms.sql.gz

Thank you for your reading, the above is the content of "how to achieve mysql sub-library backup". After the study of this article, I believe you have a deeper understanding of how to achieve mysql sub-library backup, 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: Backup sub-library script statement learning content that is time same single multiple multiple actual actually ideas situations data databases articles more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Apple Microsoft MariaDB Shulou Tech Info