在windows上运行.sh文件以从Mysql.sql文件恢复单个表
我有一个mysql数据库的备份,我只是需要一个表从它在匆忙 它是4gb的,我试着用VIM之类的程序打开它,但效果不好,我猜它太大了。即使这样,从这么多的文本中提取一个表也很困难 所以我遇到了这个: 这说明了如何使用shell脚本执行此操作。我发现你可以在windows中运行shell脚本,我正在运行windows 8.1 我不太清楚这些步骤是什么: 所以我运行cwygin并进入shell脚本窗口 我将数据库文件和mysqldumpsplitter.sh放在我创建的C:\cygwin64\usr\mysql文件夹中 然后我转到/usr/mysql并运行以下命令:在windows上运行.sh文件以从Mysql.sql文件恢复单个表,mysql,mysqldump,sh,Mysql,Mysqldump,Sh,我有一个mysql数据库的备份,我只是需要一个表从它在匆忙 它是4gb的,我试着用VIM之类的程序打开它,但效果不好,我猜它太大了。即使这样,从这么多的文本中提取一个表也很困难 所以我遇到了这个: 这说明了如何使用shell脚本执行此操作。我发现你可以在windows中运行shell脚本,我正在运行windows 8.1 我不太清楚这些步骤是什么: 所以我运行cwygin并进入shell脚本窗口 我将数据库文件和mysqldumpsplitter.sh放在我创建的C:\cygwin64\usr
sh mysqldumpsplitter.sh mydatabase.sql tbl_activity
tbl_活动是我试图访问的表。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:未找到第11行:tput:命令
mysqldumpsplitter.sh:未找到第12行:tput:命令
mysqldumpsplitter.sh:未找到第13行:tput:命令
mysqldumpsplitter.sh:未找到第14行:tput:命令
从上的mydatabase.sql提取的0表
第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转储文件,我希望能很快做到这一点。这仅仅是一个在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}"
试试UltraEdit程序:它打开文件时不会缓冲整个内容。我相信你可以使用评估版30天
奇怪的是,这是我所知道的唯一一个不缓冲整个文件的程序(Windows/Linux)。它在很多场合对我都有帮助。我不会走那么远的路。我会用我手边的东西。我想,您知道表结构,只需要数据。因此,我将在
cmd
中使用如下内容:
C:\tmp>findstr "^INSERT INTO your_table" < mydatabase.sql > filtered.sql
C:\tmp>findstr“^INSERT to your_table”filtered.sql
可以肯定的是,INSERT语句在文件中的外观您可能会运行以下操作:
C:\tmp>findstr "INSERT INTO" < mydatabase.sql | more
C:\tmp>findstr“插入”
然后按Ctrl+C退出