Recently the company has a database to be migrated, but there are more databases created, we take a script to separate the library, then upload to another host, create a new database, and then restore the database. Paste a few small scripts you wrote here,
Sub-Library Compression backup
#/bin/sh#version 0.1myuser=mysqlback[email protected] #SOCKET =/data/3306/mysql.sockmylogin= "mysql-u$myuser-p$ Mypass "mydump=" Mysqldump-u$myuser-p$mypass-b "database=" $ ($MYLOGIN-E "show databases;" | Egrep-vi "Data|_schema|mysql") "#正则for dbname in $DATABASE do mydir=/data/backup/$dbname [!-D $MYDIR] && Mkdir-p $MYDIR $MYDUMP $dbname |gzip > $MYDIR/${dbname}_$ (Date +%f). Sql.gzdone
Batch Decompression
#/bin/bashfor i in ' ls *.gz ' does gunzip $i done decompression result: Wl_smsgate_2017-04-12.sql wl_smsgate_hx_2017-04-12.sql WL _smsgate_ldkj_2017-04-12.sql Wl_smsgate_tt_2017-04-12.sqlwl_smsgate_dg_2017-04-12.sql Wl_smsgate_jjbs_ 2017-04-12.sql wl_smsgate_pc_2017-04-12.sql wl_smsgate_tt_lt_2017-04-12.sql Wl_smsgate_dxfj_2017-04-12.sql wl_sms Gate_jl_2017-04-12.sql Wl_smsgate_sb_2017-04-12.sql
Batch database creation
#/bin/bash#fun Create databasemysqluser=rootmysqlpass=winnerlook123mysqlcent= "Mysql-u $mysqluser-p$mysqlpass" Dabasename= ' cat databasename ' date2= "_2017-04-12.sql" for data in $dabasenamedo $mysqlcent-E "CREATE database if not exists $data default character set UTF8 "done
Recovering data
#/bin/bash#fun Create databasemysqluser=rootmysqlpass=winnerlook123mysqlcent= "Mysql-u $mysqluser-p$mysqlpass" Dabasename= ' cat databasename ' date2= "_2017-04-12.sql" for data in $dabasenamedo $mysqlcent-E "Use $data" && $mysqlcent-E "source/tmp/backup/$data $date2" #恢复数据done
Then examine the database's data character set and its number of data bars.
This article is from the "Keep Dreaming" blog, please be sure to keep this source http://dreamlinux.blog.51cto.com/9079323/1915152
Bulk database creation and batch data recovery