I have a little batch script that gets the temporary password from mysql.err
file.
But I have a problem when a password contains :
that is used in delimiter match resulting password will not get as is..
Is there any other approach to get correctly the password?
@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 root@localhost:" ^<%mysql_dir%\data\%ComputerName%.err') DO set temp_mysql_password="%%G"
echo.
echo.
echo Current MySQL password: %temp_mysql_password%
The mysql.err
file content is:
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 root@localhost: 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).
And the problem is with that the password
v>dqu;;&)7:Y
** that contains :
will be extracted as:
v>dqu;;&)7
.