提示:1045 access denied for user 'root'@'localhost' using password yes
This pops up when connecting to the database, and then I forgot the password, please see
Reprint please indicate the source http://blog.csdn.net/yc7369
I used to find various methods because of this problem, but none of them worked. Finally, I recorded the available methods and sorted them out today.
Linux:
Jump to the mysql folder first
#mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER= 'root';
mysql> FLUSH PRIVILEGES;
mysql> quit
# /etc/init.d/mysql restart
# mysql -uroot -p
Enter password: < enter the new password newpassword>
mysql>
Windows:
Method 1,
1 Stop the mysql service first in the service 2 Then find the my.ini file and my*.ini file under C:\Program Files\MySQL\MySQL Server 5.6 and add the parameter skip-grant-tables under [mysqld] and save it 3 Start the mysql service 4 Log in to mysql without a password at this time 5 You can view the permissions in the mysql database table But according to the method of online query processing, modify the password and report an error: skip-grant-tables startup can not modify the password update user set Password='' where Host= 'localhost'; set the password to blank 6 close the mysql service modify the my.ini file comment out the skip-grant-tables parameter save 7 start the service (the password is not required at this time and the password is blank) grant all on *.* to 'root'@'localhost' identified by '123456'; successfully exit and re-login successfully
Some friends say that 1 does not seem to work on his PC. I have encountered this too. We can learn from the Linux method, but we need to add some steps in front. This method is available for personal testing. It is opened by the moderator ACMAIN_CHM and organized by yc
Method 2,
Go to the WINDOWS command line ( under 'DOS' ), switch to your MySQL bin directory. For example, mine is C:\Program Files\MySQL\MySQL Server 5.1\bin and then type the command in bold below. Note your my.ini location. C:\Program Files\MySQL\MySQL Server 5.1\bin> mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server 5.6\my.ini" --console --skip-grant-tables 090515 22 :06:09 [Warning] The syntax '--log' is deprecated and will be removed i n MySQL 7.0. Please use '--general_log'/'--general_log_file' instead. 090515 22:06:09 [Warning] The syntax '--log_slow_queries' is deprecated and will be removed in MySQL 7.0. Please use '--slow_query_log'/'--slow_query_log_file' instead.
090515 22:06:09 [Warning] The syntax '--log' is deprecated and will be removed i
n MySQL 7.0. Please use '--general_log'/'--general_log_file' instead.
090515 22:06:09 [Warning] The syntax '--log_slow_queries' is deprecated and will
be removed in MySQL 7.0. Please use '--slow_query_log'/'--slow_query_log_file'
instead.
090515 22:06:09 [ERROR] The update log is no longer supported by MySQL in versio
n 5.0 and above. It is replaced by the binary log. Now starting MySQL with --log
-bin='' instead.
090515 22:06:09 InnoDB: Started; log sequence number 0 324221
090515 22:06:09 [Note] mysqld: ready for connections.
Version: '5.6-community-log' socket: '' port: 3306 MySQL Community Server
(GPL)
Seeing this result means that MySQL is up. Open another DOS window, switch to the mysql bin directory, C:\Program Files\MySQL\MySQL Server 5.1\bin> mysql -uroot mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 http://blog.csdn.net/yc7369
Reprint please indicate the source http://blog.csdn.net/yc7369
If the above method is not available, welcome to screenshot and leave a message, and we can solve it together