ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' workaround

Source: Internet
Author: User

System: Centos 6.5 64-bit

mysql:5.1.73


Today want to do a database test experiment, incredibly forget the MySQL data password. This is enabled using Safe mode.


[[email protected] ~]# service mysqld stop #先停止数据库

Stopping mysqld: [OK]

[Email protected] ~]# mysqld_safe--skip-grant-tables & #利用安全模式启用数据库

[1] 1547

[Email protected] ~]# 150403 10:43:26 mysqld_safe Logging to '/var/log/mysqld.log '.

150403 10:43:26 Mysqld_safe starting mysqld daemon with databases From/var/lib/mysql

Mysql-uroot #可以这样输入, you can also enter the MySQL return directly, because the security mode is root permissions.

Welcome to the MySQL Monitor. Commands End With; or \g.

Your MySQL Connection ID is 1

Server version:5.1.73 Source Distribution


Copyright (c) and/or, Oracle, its affiliates. All rights reserved.


Oracle is a registered trademark of the Oracle Corporation and/or its

Affiliates. Other names trademarks of their respective

Owners.


Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.


mysql> use MySQL; #切换到mysql数据库

Database changed


mysql> UPDATE user SET Password=password (' root ') where user= ' root '; #更新 root user password is root, this is changed according to your own.

Query OK, 0 rows affected (0.01 sec)

Rows matched:0 changed:0 warnings:0


Mysql> FLUSH privileges; #强制刷新数据库记录.

Query OK, 0 rows Affected (0.00 sec)


Mysql> quit #退出

Bye


I believe that many friends will restart the database directly, I have the same problem. Because we have just enabled MySQL in safe mode, there will be a mysqld_safe number of processes running now:0 in the process, and you will have to restart MySQL to log on after the process of this safe mode is over.



[Email protected] ~]# killall-9 mysqld #结束进程里残留的Mysql进程.

[Email protected] ~]#/usr/bin/mysqld_safe:line 158:1634 killed Nohup/usr/libexec/mysqld--basedir=/ usr--datadir=/var/lib/mysql--user=mysql--skip-grant-tables--log-error=/var/log/mysqld.log--pid-file=/var/run/ Mysqld/mysqld.pid--socket=/var/lib/mysql/mysql.sock </dev/null >>/var/log/mysqld.log 2>&1

150403 10:46:47 mysqld_safe number of processes running now:0

150403 10:46:47 Mysqld_safe mysqld restarted


[[email protected] ~]# service mysqld start

Starting mysqld: [OK]

[Email protected] ~]# mysql-uroot-p

Enter the password you just changed to enter the database.





ERROR 1045 (28000): Access denied for user ' root ' @ ' localhost ' workaround

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.