[英]Windows Batch File: restore mysql database from dump file which name start with
This is the way to restore a mysql database from command line: 这是从命令行还原mysql数据库的方法:
mysql -u username -pPASSWORD database_name < file-20140410.sql
But imagine that I don't know the name of the file, just I know that starts with "file-" and the extension is ".sql" 但是想象一下,我不知道文件名,只是我知道以“ file-”开头,扩展名为“ .sql”
but this doesn't work: 但这不起作用:
//this doesn't work
mysql -u username -pPASSWORD database_name < file-*.sql
I need dump I database knowing only the begin of the filename. 我需要只知道文件名开头的转储数据库。
thanks in advance ! 提前致谢 !
If you can't find the file, search in a CMD-window. 如果找不到文件,请在CMD窗口中搜索。 Go to each drive, change to root directory and search for the file, ie:
转到每个驱动器,转到根目录并搜索文件,即:
REM change drive letter
C:
REM change current directory to root directory
CD \
REM search your file in all subdirectories
DIR file-*.sql /s
At the end thanks to "esac" it is SOLVED, but with some small changes. 最后,由于使用了“ esac”,因此已解决,但有一些小的更改。 This is the final script:
这是最终的脚本:
forfiles /m file-*.sql /c "cmd /c mysql -u USERNAME -pPASSWORD database_name < @file"
使用forfiles
命令可使用通配符并对每个文件执行操作。
c:\test>forfiles /m file-*.sql /c "mysql -u username -pPASSWORD database_name ^< @file"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.