首页 文章

更改密码后无法登录mysql 5.7.9

提问于
浏览
2

我安装了Mysql Ver 14.14 Distrib 5.7.9, for Linux (x86_64) using EditLine wrapper On CentOS Linux release 7.1.1503

我使用此命令更改了root密码:

alter user 'root'@'localhost' identified by 'XXXXXXX';  
flush privileges;

重新登录后

[root@server ~]# mysql -u root -p
Enter password:

ERROR 1524(HY000):未加载插件'* A6074285732753D325C55AD74E7517CF442C1A81'

3 回答

  • 0

    自早期版本的mySQL(我使用5.7.10)以来,有两件事发生了变化:

    • systemd 现在用来照顾mySQL而不是 mysqld_safe (这就是我收到 -bash: mysqld_safe: command not found 错误的原因 - 它没有安装)

    • user 表结构已更改 .

    因此,要重置root密码,您仍然可以使用 --skip-grant-tables 选项启动mySQL并更新 user 表,但是如何更改它 .

    1. Stop mysql:
    systemctl stop mysqld
    
    2. Set the mySQL environment option 
    systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
    
    3. Start mysql usig the options you just set
    systemctl start mysqld
    
    4. Login as root
    mysql -u root
    
    5. Update the root user password with these mysql commands
    mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword')
        -> WHERE User = 'root' AND Host = 'localhost';
    mysql> FLUSH PRIVILEGES;
    mysql> quit
    
    6. Stop mysql
    systemctl stop mysqld
    
    7. Unset the mySQL envitroment option so it starts normally next time
    systemctl unset-environment MYSQLD_OPTS
    
    8. Start mysql normally:
    systemctl start mysqld
    
    Try to login using your new password:
    7. mysql -u root -p
    

    Reference

    正如它在http://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html所说,

    注意从MySQL 5.7.6开始,对于使用RPM分发的MySQL安装,服务器启动和关闭由systemd在几个Linux平台上管理 . 在这些平台上,不再安装mysqld_safe,因为它是不必要的 . 有关更多信息,请参见第2.5.10节“使用systemd管理MySQL服务器” .

    这会将你带到http://dev.mysql.com/doc/refman/5.7/en/server-management-using-systemd.html,它会在页面底部提到 systemctl set-environment MYSQLD_OPTS= .

    密码重置命令位于http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html的底部

  • 1

    更改任何用户,尤其是root用户时,应该在mysql用户表上使用update .

    您应该按照以下步骤重置它:

    How to reset the root password for mysql:
    Stop mysql:
    1. service mysql stop
    
    Run mysql with skip grants to be able to login without any password
    2. mysqld_safe --skip-grant-tables &
    
    Login as root
    3. mysql -u root
    
    4. mysql commands:
    mysql> use mysql;
    mysql> update user set password=PASSWORD("YourPWHere") where User='root';
    mysql> flush privileges;
    mysql> quit
    
    Stop mysql
    5. service mysql stop
    
    Start mysql normally:
    6. service mysql start
    
    Try to login using your new password:
    7. mysql -u root -p
    

    更新:

    显然这种方法不适用于5.7,请参考HereHere .

  • 17

    使用以下步骤重置密码 .

    $ sudo systemctl start mysqld
    

    重置MySql服务器root密码 .

    $sudo grep 'temporary password' /var/log/mysqld.log
    

    Output Something like-:

    10.744785Z 1 [Note] A temporary password is generated for root@localhost: o!5y,oJGALQa
    

    在重置mysql_secure_installation过程中使用上述密码 .

    $ sudo mysql_secure_installation
           Securing the MySQL server deployment.
    
           Enter password for user root:
    

    您已成功重置MySql Server的root密码 . 使用以下命令检查mysql服务器连接与否 .

    $ mysql -u root -p
    

    看我的文章:Install Latest MySQL 5.7 on RHEL/Centos 7

相关问题