我有一个小批量脚本从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