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

提示:access denied for user 'root'@'localhost' using password yes

系统:windows7 64

1. 管理员登陆系统,停止 MySQL 服务或者结束 MySQL 进程。



2. 启动 WINDOWS 的命令行窗体(即通常的 DOS 窗体),切换到你的 “MySQLin” 文件夹下。
比如我的是 “D:SERVERMySQLin”,然后运行以下的粗体的命令:
(注意你的 “my-default.ini” 位置)

Microsoft Windows7 [版本号 5.1.2600]
(C) 版权全部 1985-2001 Microsoft Corp.

C:Documents and SettingsMMC>d:

D:>cd D:SERVERMySQLin

D:SERVERMySQLin>mysqld --defaults-file="D:SERVERMySQL5122my-default.ini" --console --skip-grant-tables
090801 4:43:54 InnoDB: Started; log sequence number 0 585546
090801 4:43:54 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
090801 4:43:54 [Note] mysqld: ready for connections.
Version: '5.1.22-rc-community' socket: '' port: 3306 MySQL Community Server (GPL)
_

仅仅要出现以下信息,就说明 MySQL 已经起来了。



Version: '5.1.22-rc-community' socket: '' port: 3306 MySQL Community Server (GPL)

3. 不关闭此命令行窗体。又一次打开一个命令行窗体。相同切到 “mysqlin” 文件夹下。然后运行以下的粗体的命令:

C:Documents and SettingsMMC>d:

D:>cd D:SERVERMySQLin

D:SERVERMySQLin>mysql -u root mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.1.22-rc-community MySQL Community Server (GPL)

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql>

到这步。我想不论什么一个使用 MySQL 的人都知道后面要做什么了。(^a^)
mysql>
mysql> UPDATE user SET Password=PASSWORD('mynewpass') where USER='root';
Query OK, 2 rows affected (0.05 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)
mysql> quit
Bye

4. 好了到此步。能够关闭第一个 DOS 窗体了。打开系统服务控制窗体(控制面板--管理工具--服务)。启动 MySQL 服务。



5. 在剩下的第二个 DOS 窗体中,用新的 ROOT 密码连接 MySQL。



D:SERVERMySQL5122in>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.1.22-rc-community MySQL Community Server (GPL)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> quit
Bye

至此,系统恢复 ROOT 用户管理权限完毕。



【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/yjbjingcha/p/8343226.html