Can not login to mysql 5.7.9 after change password

倾然丶 夕夏残阳落幕 提交于 2019-11-29 02:00:10

问题


I have installed Mysql Ver 14.14 Distrib 5.7.9, for Linux (x86_64) using EditLine wrapper On CentOS Linux release 7.1.1503

I Changed root password using this command:

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

After re-login

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

ERROR 1524 (HY000): Plugin '*A6074285732753D325C55AD74E7517CF442C1A81' is not loaded


回答1:


Two things have changed since earlier versions of mySQL (I''m using 5.7.10):

  1. systemd is now used to look after mySQL instead of mysqld_safe (which is why I was getting the -bash: mysqld_safe: command not found error - it's not installed)

  2. The user table structure has changed.

So to reset the root password, you still start mySQL with --skip-grant-tables options and update the user table, but how you do it has changed.

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

As it says at http://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html,

Note

As of MySQL 5.7.6, for MySQL installation using an RPM distribution, server startup and shutdown is managed by systemd on several Linux platforms. On these platforms, mysqld_safe is no longer installed because it is unnecessary. For more information, see Section 2.5.10, “Managing MySQL Server with systemd”.

Which takes you to http://dev.mysql.com/doc/refman/5.7/en/server-management-using-systemd.html where it mentions the systemctl set-environment MYSQLD_OPTS= towards the bottom of the page.

The password reset commands are at the bottom of http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html




回答2:


You should use update on mysql user table when changing any user, especially root.

You should follow these steps to reset it:

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

Update:

Apparently this method will not work for 5.7, please refer to Here and Here instead.




回答3:


Use the below Steps to reset the password.

$ sudo systemctl start mysqld

Reset the MySql server root password.

$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

Use the above password during reset mysql_secure_installation process.

   $ sudo mysql_secure_installation
       Securing the MySQL server deployment.

       Enter password for user root: 

You have successfully reset the root password of MySql Server. Use the below command to check the mysql server connecting or not.

$ mysql -u root -p

See my article: Install Latest MySQL 5.7 on RHEL/Centos 7



来源:https://stackoverflow.com/questions/33374314/can-not-login-to-mysql-5-7-9-after-change-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!