我有一個mysql數據庫的備份,我只需要一張表就可以了。在windows上運行.sh文件以從Mysql .sql文件中恢復單個表
它的4gb和iive試圖用VIM這樣的程序打開它,但它並不好,猜測它太大了。即使這樣做試圖從這麼多文本中提取一張表格也很困難。
所以我碰到這樣的: http://kedar.nitty-witty.com/blog/mydumpsplitter-extract-tables-from-mysql-dump-shell-script
這解釋瞭如何使用shell腳本做到這一點。我發現與http://cygwin.com你可以在Windows運行shell腳本,即時運行Windows 8.1。
我不是真正清楚什麼步驟是:
所以我來說cwygin並進入shell腳本窗口 我把我的數據庫文件,並在C mysqldumpsplitter.sh:\ cygwin64的\ usr \ mysql的文件夾我創建。
然後我去到/ usr/mysql和我運行此:
sh mysqldumpsplitter.sh mydatabase.sql tbl_activity
tbl_activity是表IM試圖訪問。和mydatabase.sql是SQL備份
但是當我跑,我得到
mysqldumpsplitter.sh:5號線:tput的:命令未找到 mysqldumpsplitter.sh:6號線:tput的:命令未找到 mysqldumpsplitter .SH:行7:tput的:命令未找到 mysqldumpsplitter.sh:行8:tput的:命令未找到 mysqldumpsplitter.sh:行9:tput的:命令未找到 mysqldumpsplitter.sh:線10:tput的:命令未找到 mysqldumpsplitter.sh:line 11:tput:command not found mysqldumpsplitter.sh:line 12:tput:command not found my sqldumpsplitter.sh:第13行:tput:命令未找到 mysqldumpsplitter.sh:第14行:tput:命令未找到 0從mydatabase.sql中提取表。
線5 = 14低於
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
txtred=$(tput setaf 1) # Red
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtpur=$(tput setaf 5) # Purple
txtcyn=$(tput setaf 6) # Cyan
txtwht=$(tput setaf 7) # White
txtrst=$(tput sgr0) # Text reset
雖然我可能獲得訪問Ubuntu的機器上並運行這個(我認爲這將更好地工作,在那裏)我將不得不等待數小時,4GB的.SQL轉儲上傳和IM希望快速做到這一點。它只是一個黑客運行在Windows上,我應該切換到Ubuntu來運行它呢?
完全.SH這裏文件,因爲它的小
#!/bin/sh
# http://kedar.nitty-witty.com
#SPLIT DUMP FILE INTO INDIVIDUAL TABLE DUMPS
# Text color variables
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
txtred=$(tput setaf 1) # Red
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtpur=$(tput setaf 5) # Purple
txtcyn=$(tput setaf 6) # Cyan
txtwht=$(tput setaf 7) # White
txtrst=$(tput sgr0) # Text reset
TARGET_DIR="."
DUMP_FILE=$1
TABLE_COUNT=0
if [ $# = 0 ]; then
echo "${txtbld}${txtred}Usage: sh MyDumpSplitter.sh DUMP-FILE-NAME${txtrst} -- Extract all tables as a separate file from dump."
echo "${txtbld}${txtred} sh MyDumpSplitter.sh DUMP-FILE-NAME TABLE-NAME ${txtrst} -- Extract single table from dump."
echo "${txtbld}${txtred} sh MyDumpSplitter.sh DUMP-FILE-NAME -S TABLE-NAME-REGEXP ${txtrst} -- Extract tables from dump for specified regular expression."
exit;
elif [ $# = 1 ]; then
#Loop for each tablename found in provided dumpfile
for tablename in $(grep "Table structure for table " $1 | awk -F"\`" {'print $2'})
do
#Extract table specific dump to tablename.sql
sed -n "/^-- Table structure for table \`$tablename\`/,/^-- Table structure for table/p" $1 > $TARGET_DIR/$tablename.sql
TABLE_COUNT=$((TABLE_COUNT+1))
done;
elif [ $# = 2 ]; then
for tablename in $(grep -E "Table structure for table \`$2\`" $1| awk -F"\`" {'print $2'})
do
echo "Extracting $tablename..."
#Extract table specific dump to tablename.sql
sed -n "/^-- Table structure for table \`$tablename\`/,/^-- Table structure for table/p" $1 > $TARGET_DIR/$tablename.sql
TABLE_COUNT=$((TABLE_COUNT+1))
done;
elif [ $# = 3 ]; then
if [ $2 = "-S" ]; then
for tablename in $(grep -E "Table structure for table \`$3" $1| awk -F"\`" {'print $2'})
do
echo "Extracting $tablename..."
#Extract table specific dump to tablename.sql
sed -n "/^-- Table structure for table \`$tablename\`/,/^-- Table structure for table/p" $1 > $TARGET_DIR/$tablename.sql
TABLE_COUNT=$((TABLE_COUNT+1))
done;
else
echo "${txtbld}${txtred} Please provide proper parameters. ${txtrst}";
fi
fi
#Summary
echo "${txtbld}$TABLE_COUNT Table extracted from $DUMP_FILE at $TARGET_DIR${txtrst}"