win7 Access denied for user root'@'localhost

近来在连接Mysql时遇见windows: Access denied for user 'root'@'localhost'这样的问题,苦恼了好一段时间,下面给大家分享一下解决办法

操作方法

  • 01

    点击“开始”->“程序”->"运行",以管理员的身份运行。

  • 02

    在命令行中输入  C:\Documents and Settings\MMC>e:,e盘为Mysql服务所在的盘符

  • 03

    打开Mysql.bin目录,在命令行输入E:\>cd E:\mysql-5.5.49-win32\mysql-5.5.49-win32\bin

  • 04

    接着在命令行中输入 E:\SERVER\MySQL5122\bin>mysqld --defaults-file=" E:\mysql-5.5.49-win32\mysql-5.5.49-win32\ my.ini" --console --skip-grant-tables, 只要出现下面信息,就说明 MySQL 已经起来了。 Version: '5.1.22-rc-community' socket: '' port: 3306 MySQL Community Server

  • 05

    紧接着,不关闭此命令行窗口,重新打开一个命令行窗口,同样切到 “mysql\bin” 目录下,然后执行下面的命令 C:\Documents and Settings\MMC>e: E:\>cd E:\mysql-5.5.49-win32\mysql-5.5.49-win32\bin D:\>cd D:\SERVER\MySQL5122\bin E:\SERVER\MySQL5122\bin>mysql -u root mysql 出现Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.1.22-rc-community MySQL Community Server (GPL)Type 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql>

  • 06

    接着在命令行中输入粗体命令: 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> quitBye

  • 07

    好了到此步,可以关闭第一个 DOS 窗口了。打开系统服务控制窗口(控制面板--管理工具--服务),启动 MySQL 服务。

  • 08

    在剩下的第二个 DOS 窗口中,用新的 ROOT 密码连接 MySQL。 D:\SERVER\MySQL5122\bin>mysql -u root -pEnter 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> quitBye 至此,系统恢复 ROOT 用户管理权限完成。

(0)

相关推荐