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

The operation of MySQL database backup script by database and table

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article is mainly about the operation of MySQL sub-database sub-table backup database script, if you are interested, let's take a look at this article. I believe that after reading the operation of MySQL sub-database sub-table backup database script, it is of some reference value to everyone.

Backup database script

[root@*** script] # cat store_backup.sh

#! / bin/sh

MYUSER=root

MYPASS=qwe123

SOCKET=/data/3306/mysql.sock

MYLOGIN= "mysql-u$MYUSER-p$MYPASS-S $SOCKET"

MYDUMP= "mysqldump-u$MYUSER-p$MYPASS-S$SOCKET-B"

DATABASE= "$($MYLOGIN-e" show databases; "| egrep-vi" Data | _ schema | mysql ")"

For dbname in $DATABASE

Do

MYDIR=/server/backup/$dbname

[!-d $MYDIR] & & mkdir-p $MYDIR

$MYDUMP $dbname | gzip > $MYDIR/$ {dbname} _ $(date +% F) .sql.gz

Done

[root@*** script] # sh store_backup.sh

[root@*** script] # tree / server/backup/

/ server/backup/

├── test

│ └── test_2017-06-21.sql.gz

└── wordpress

└── wordpress_2017-06-21.sql.gz

2 directories, 2 files

Mysql sub-library sub-table backup script

[root@*** script] # cat mysql_table.sh

#! / bin/sh

USER=root

PASSWD=qwe123

SOCKET=/data/3306/mysql.sock

MYLOGIN= "mysql-u$USER-p$PASSWD-S$SOCKET"

MYDUMP= "mysqldump-u$USER-p$PASSWD-S$SOCKET"

DATEBASE= "$($MYLOGIN-e" show databases; "| egrep-vi" Data | _ schema | mysql ")"

For dbname in $DATEBASE

Do

TABLE= "$($MYLOGIN-e" use $dbname;show tables; "| sed '1d')"

For tname in $TABLE

Do

MYDIR=/server/backup/$dbname/$ {dbname} _ $(date +% F)

[!-d $MYDIR] & & mkdir-p $MYDIR

$MYDUMP $dbname $tname | gzip > $MYDIR/$ {dbname} _ ${tname} _ $(date +% F) .sql.gz

Done

Done

Tips:

MySQL 5.6warning message command line interface can be insecure repair

Enter the password on the command line and you will be prompted with these security warnings.

Warning: Using a password on the command line interface can be insecure.

Note: either mysql-u root-pPASSWORD or mysqldump-u root-pPASSWORD will output such a warning.

1. For mysql

Change mysql-uroot-pPASSWORD to mysql-uroot-p by entering the password.

2. Mysqldump is more troublesome, which is usually written in scripts scripts.

Solution:

How to avoid the appearance of mysqldump (Warning: Using a password on the command line interface can be insecure.) Where's the warning message?

Vim / data/3306/my.cnf

[mysqldump]

User=your_backup_user_name

Password=your_backup_password

After you modify the configuration file, you only need to execute the mysqldump script. User name and password information is not required in the backup script.

The above about MySQL sub-database sub-table backup database script operation details, is it helpful to everyone? If you want to know more about it, you can continue to follow our industry information section.

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