数据库名列表放入一个文件里面
# cat 00db.txt information_schema db_app_cms db_eop db_leader_cms db_leader_comment
mysqldump出来的sql数据放入一个文件里面
# cat 00dbsql.txt -rw-r--r-- 1 root root 970701283 May 16 03:39 information_schema-2017-05-16-033001.sql -rw-r--r-- 1 root root 32156 May 16 03:39 db_app_cms-2017-05-16-033001.sql -rw-r--r-- 1 root root 169522095206 May 16 05:50 db_eop-2017-05-16-033001.sql -rw-r--r-- 1 root root 99699 May 16 05:50 db_leader_cms-2017-05-16-033001.sql -rw-r--r-- 1 root root 256290013 May 16 05:51 db_leader_comment-2017-05-16-033001.sql
批量建库和导入数据脚本
# cat 00createdb.sh #!/bin/bash for i in `cat 00db.txt` do for j in `cat /data/backup/00dbsql.txt | awk -F ‘ ‘ ‘{print $9}‘ ` do if [[ $j == *"$i"* ]]; then mysql -uroot -proot -S /data/mysql_data/sock/my3306.sock -e "create database $i;" mysql -uroot -proot -S /data/mysql_data/sock/my3306.sock $i < $j echo $i fi done done
执行脚本
#nohup 00createdb.sh &
时间: 2024-09-30 10:51:49