第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
本篇文章到這里就已經全部結束了,更多其他精彩內容可以關注PHP中文網的MySQL教程視頻欄目!
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com