Get the App
SLTechnology News&Howtos  ›  Database  › 

How to create a backup script for mysql Database

Shulou Source: shulou.com Published: 2022-06-01 19:49:57 10月05日 Update

This article mainly introduces how to create a sub-database backup script for mysql database. The content of the article is carefully selected and edited by the author. It has a certain pertinence and is of great significance to everyone. The following is to learn with the author how to create a sub-database backup script for mysql database.

Mysql database sub-library backup script

Version 1

For dbname in `mysql-uroot-poldboy123-e "show databases;" | grep-Evi "database | informa | perfor" `

Do

Mysqldump-uroot-poldboy123-- events-B $dbname | gzip > / opt/bak/$ {dbname} _ bak.sql.gz

Done

Version 2

#! / bin/bash

MYUSER=root

MYPASS=oldboy123

MYCMD= "mysql-u$MYUSER-p$MYPASS-- default-character-set=utf8"

MYDUMP= "mysqldump-u$MYUSER-p$MYPASS-- default-character-set=utf8-- events-B"

DBLIST= `$ MYCMD-e "show databases;" | grep-Evi "database | informa | perfor" `

[!-d / opt/bak] & & mkdir-p / opt/bak

For dbname in $DBLIST

Do

$MYDUMP $dbname | gzip > / opt/bak/$ {dbname} _ bak.sql.gz

Done

Multi-instance sub-database backup

#! / bin/bash

MYUSER=root

MYPASS=oldboy123

SOCKET=/data/3306/mysql.sock

MYCMD= "mysql-u$MYUSER-p$MYPASS-default-character-set=utf8-S $SOCKET"

MYDUMP= "mysqldump-u$MYUSER-p$MYPASS-- default-character-set=utf8-S $SOCKET-- events-B"

DBLIST= `$ MYCMD-e "show databases;" | grep-Evi "database | informa | perfor" `

[!-d / opt/bak] & & mkdir-p / opt/bak

For dbname in $DBLIST

Do

$MYDUMP $dbname | gzip > / opt/bak/$ {dbname} _ bak.sql.gz

Done

After reading the above about mysql database how to create sub-database backup script, many readers must have some understanding, if you need to get more industry knowledge and information, you can continue to follow our industry information column.

Tags: Sub-library backup data database script version author industry information content examples meaning articles more friends columns knowledge readers information or Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB NVidia Linux Redmi macOS