第1步:下载MySQL dump拆分剧本
在零丁的表特定文件备份中拆分完全的mysqldump数据库备份文件。建立一个名为splitdb.sh的文件,并在个中复制下面的剧本。
#!/bin/bash #### # Split MySQL dump SQL file into one file per table # based on http://blog.tty.nl/2011/12/28/splitting-a-database-dump #### if [ $# -lt 1 ] ; then echo "USAGE $0 DUMP_FILE [TABLE]" exit fi if [ $# -ge 2 ] ; then csplit -s -ftable $1 "/-- Table structure for table/" "%-- Table structure for table `$2`%" "/-- Table structure for table/" "%40103 SET TIME_ZONE=@OLD_TIME_ZONE%1" else csplit -s -ftable $1 "/-- Table structure for table/" {*} fi [ $? -eq 0 ] || exit mv table00 head FILE=`ls -1 table* | tail -n 1` if [ $# -ge 2 ] ; then mv $FILE foot else csplit -b '%d' -s -f$FILE $FILE "/40103 SET TIME_ZONE=@OLD_TIME_ZONE/" {*} mv ${FILE}1 foot fi for FILE in `ls -1 table*`; do NAME=`head -n1 $FILE | cut -d$'x60' -f2` cat head $FILE foot > "$NAME.sql" done rm head foot table*
第2步:从dump中提取一切表
关于这个例子,有一个名为mydb.sql的转储文件,要想在每一个表的小备份中拆分。为此,须要建立了一个新目次/ opt / splitdb,并在此目次中复制了名为splitDB.sh的剧本。如今运用以下敕令提取单个备份文件中的一切表。
#cd / opt / splitdb #sh splitDB.sh mydb.sql
第3步:从dump中提取单个表
假如我们只想提取一个表,我们能够运用以下敕令。比方,要想只拆分名为my_tbl1和my_tbl2的表。它将在当前目次中提取名为my_tbl1.sql和my_tbl2.sql的备份。
#cd / opt / splitdb #sh splitDB.sh mydb.sql my_tbl1 #sh splitDB.sh mydb.sql my_tbl2
本篇文章到这里就已悉数完毕了,更多其他精彩内容能够关注ki4网的MySQL教程视频栏目!
以上就是怎样从完全的MySQL DB转储文件中提取表备份的细致内容,更多请关注ki4网别的相干文章!