[已解决][40元已支付] 请问如何截取生成的随机密码并保存便于后续调用?
本帖最后由 xuc 于 2022-4-20 10:42 编辑
在写一个一键安装mysql的bat,输入mysqld --initialize --console命令后会生成一个随机密码,(最后12位,如:A temporary password is generated for root@localhost: C6lGXsJfk,4D),需要记录下这个密码,再执行mysqld --install mysql,net start mysql,mysql -uroot -p,然后输入刚刚的密码,最后执行ALTER USER 'root'@'localhost' IDENTIFIED BY '111111';
目前不知道如何保存密码并在后续需要输入的时候自动调用
已经写好的内容截取部分如下:
cd ./bin
mysqld --initialize --console
mysqld --install mysql
if !errorlevel! equ 0 (
echo ******************安装mysql服务成功*******************
echo.
) else (
echo ******************安装mysql服务失败*******************
echo 安装mysql服务失败 >> ../install_log.txt
echo.
pause
exit
)
echo ******************开始启动mysql服务*******************
echo.
net start mysql
if !errorlevel! equ 0 (
echo ******************启动mysql服务成功*******************
echo 1 >> ./is_install.txt
echo.
) else (
echo ******************启动mysql服务失败*******************
echo 启动mysql服务失败 >> ../install_log.txt
echo.
pause
exit
)
实际运行生成密码部分如下:
D:\mysql-8.0.28-winx64\mysql-8.0.28-winx64\bin>mysqld --initialize --console
2022-04-19T11:45:10.951279Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2022-04-19T11:45:10.951298Z 0 [System] [MY-013169] [Server] D:\mysql-8.0.28-winx64\mysql-8.0.28-winx64\bin\mysqld.exe (mysqld 8.0.28) initializing of server in progress as process 14012
2022-04-19T11:45:10.951379Z 0 [ERROR] [MY-010338] [Server] Can't find error-message file 'D:\mysql-8.0.26-winx64\mysql-8.0.26-winx64\share\errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2022-04-19T11:45:10.990057Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-04-19T11:45:11.514595Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-04-19T11:45:12.296844Z 0 [Warning] [MY-013829] [Server] Missing data directory for ICU regular expressions: D:\mysql-8.0.26-winx64\mysql-8.0.26-winx64\lib\private\.
2022-04-19T11:45:13.580235Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: C6lGXsJfk,4D
另外,安装过程参考https://blog.csdn.net/a802976/article/details/119255644?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164984901516782184696627%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=164984901516782184696627&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-2-119255644.142^v7^control,157^v4^control&utm_term=mysql%E4%B8%8B%E8%BD%BD&spm=1018.2226.3001.4187,配置环境变量部分已写好,只需要截取12位密码保存,并在执行mysqld --install mysql,net start mysql,mysql -uroot -p这三个命令后调用 |