Cannot reset mysql password as root

╄→尐↘猪︶ㄣ 提交于 2020-01-03 02:54:15

问题


i am using CentOs with mysql 5 version, forgot my password, and i cannot reset it, what i did is

/etc/init.d/mysqld stop

mysqld_safe --skip-grant-tables &
mysql -u root

mysql>  update mysql.user set password=PASSWORD("pass") where User='root';

got this message

Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

mysql> flush privileges; exit;
Query OK, 0 rows affected (0.00 sec)

Stopped and strated mysql but its anyway

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

i have tried this solution mysql official site, not working anyway. Any suggestions?

UPDATE

My main user was admin not root so i changed password for admin all is ok now, sorry for this. thanks everyone.


回答1:


Have a closer look at your error message:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
                                                               ^^^^^^^^^^^^^^^^^^

You might have set a new password, but you are not using it to connect.




回答2:


This worked for me

   UPDATE mysql.user SET Password=PASSWORD('foobar') WHERE User='tom' AND Host='localhost';

This did not work for me

   SET PASSWORD FOR 'user-name-here'@'hostname-name-here' = PASSWORD('new-password-here');



回答3:


Access denied for user 'root'@'localhost'  (using password: NO)

make sure what ever is trying to login is definatly sending a password




回答4:


Try to flush privalages after resetting the password:

    UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
    FLUSH PRIVILEGES;

If that doesn't work follow these steps: How to Reset the Root Password



来源:https://stackoverflow.com/questions/13916532/cannot-reset-mysql-password-as-root

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