无法重置mysql' root'密码

时间:2017-07-18 08:52:28

标签: mysql

我已经安装了mysql 5.7.18。安装后,root用户的密码为null。 我已尝试mysql_secure_instattation并按照查询重置密码。

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyPassword';

UPDATE mysql.user
    SET authentication_string = PASSWORD('MyPassword'), password_expired = 'N'
    WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;

这些方法成功执行但仍然是mysql root用户连接NULL密码。 我该怎么办?

3 个答案:

答案 0 :(得分:0)

  1. 更糟糕的是停止服务器:如果它作为服务运行,请使用任务管理器。 (或服务)
  2. 创建一个文件C:\ mysql-init.txt(例如),键入:
  3.   

    更改用户'root'@'localhost'通过'MyNewPass'识别;

    1. 打开cmd(以管理员身份)并运行:
    2. C:\> cd "C:\Program Files\MySQL\MySQL Server 5.7\bin"
      C:\> mysqld --init-file=C:\\mysql-init.txt
      

      注意:如果您使用的是MySQL 5.7.5及更早版本,请使用以下命令更改命令行:

      SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
      

答案 1 :(得分:0)

您也可以使用以下命令更新MySQL密码:

Description:

Parameter 0 of constructor in com.mportal.ec.error.DefaultExceptionHandler required a single bean, but 2 were found:
    - linkRelationMessageSource: defined by method 'linkRelationMessageSource' in class path resource [org/springframework/hateoas/config/HateoasConfiguration.class]
    - resourceDescriptionMessageSourceAccessor: defined by method 'resourceDescriptionMessageSourceAccessor' in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

答案 2 :(得分:0)

这是由于MySQL对root用户使用unix_socket插件而不是mysql_native_password插件,这意味着mysql信任Linux root用户的凭据。如果您以Linux超级用户登录,则MySQL不会要求提供MySQL超级用户的安全凭证。因此,即使成功地为MySQL根用户更改了密码,它也仍然没有密码连接。