Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create a backup script for mysql Database

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report