简体   繁体   中英

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 -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"

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. 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. 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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM