mysql安装:“root@localhost is created with an empty password !”,而非A temporary password is generated for

问题:在安装mysql时,打开DESKTOP-8UNK26K.err未发现密码,发现:

[Warning] root@localhost is created with an empty password ! Please
consider switching off the --initialize-insecure option.

而非:

[Warning] A temporary password is generated for root@localhost:
**********

原因:
mysql官网已经给出解决方案及原因:

The server creates a 'root'@'localhost' superuser account and other reserved accounts (see Reserved Accounts). Some reserved accounts are locked and cannot be used by clients, but 'root'@'localhost' is intended for administrative use and you should assign it a password.

Server actions with respect to a password for the 'root'@'localhost' account depend on how you invoke it:

With --initialize but not --initialize-insecure, the server generates a random password, marks it as expired, and writes a message displaying the password:

[Warning] A temporary password is generated for root@localhost:
iTag*AfrH5ej
With --initialize-insecure, (either with or without --initialize because --initialize-insecure implies --initialize), the server does not generate a password or mark it expired, and writes a warning message:

[Warning] root@localhost is created with an empty password ! Please
consider switching off the --initialize-insecure option.
For instructions on assigning a new 'root'@'localhost' password, see Post-Initialization root Password Assignment.

大概意思就是,如果之前初始化数据库时使用的是–initialize-insecure 命令,那么就不会出现密码。如果以–initialize初始化数据库,就会出现密码。initialize意为“不安全的,不可靠的”,这也就解释了为什么加上他就没有出现密码,及root的密码为空。

解决:
1、删除自己创建的data文件夹
2、以管理员身份cmd进入bin目录,关闭mysqld服务

D:\Program ~\MySQL\bin>mysqld -remove MySQL
Service successfully removed.

3、在bin目录执行mysqld --initialize,程序会自动创建刚才删掉的那个文件夹
4、在bin目录执行mysqld --install,重新安装mysql服务
5、在bin目录运行net start mysal,启动mysql服务
6、进入程序自动创建的那个文件夹,打开DESKTOP-8UNK26K.err,即可发现密码,问题解决。

你可能感兴趣的:(mysql安装:“root@localhost is created with an empty password !”,而非A temporary password is generated for)