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

Batch creation of database and batch data recovery

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

Share

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

Recently, the company has a database that needs to be migrated, but there are many databases created in it. We adopt scripts to backup the database separately, then upload it 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= mysqlbackMYPASS=databack@162.com#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")" #regular 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` do 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_smsgate_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

recover 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 "#Recover data done

Then check the database's data character set and its number of data entries.

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