我有一個小批量腳本從mysql.err
文件獲取臨時密碼。包含完整字符串分隔符的提取字符串
但我有一個問題,當一個密碼包含:
是在分隔符匹配使用導致密碼不會得到原樣..
是否有任何其他的方法來得到正確的密碼?
@echo off
setlocal enableextensions enabledelayedexpansion
set mysql_dir=C:\database\mysql
echo.
echo.
echo Search For Current MySQL Password
FOR /F "tokens=4 delims=:" %%G in ('find /I "A temporary password is generated for [email protected]:" ^<%mysql_dir%\data\%ComputerName%.err') DO set temp_mysql_password="%%G"
echo.
echo.
echo Current MySQL password: %temp_mysql_password%
的mysql.err
文件內容是:
2017-08-31T07:38:36.195916Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-08-31T07:38:36.205943Z 22 [Note] A temporary password is generated for [email protected]: v>dqu;;&)7:Y
2017-08-31T07:38:42.510215Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
而問題是,密碼
v>dqu;;&)7:Y
**包含已:
將被提取爲:
v>dqu;;&)7
。
謝謝你的時間!它是否按預期工作。不錯的見解! – oriceon