ITPub博客

首页 > 数据库 > MySQL > Mysql:ERROR 1045 (28000): Access denied for user 'root'@'localhost'

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

原创 MySQL 作者:parknkjun 时间:2015-05-12 22:56:53 0 删除 编辑
1、登陆mysql时报如下错误:
C:\Users\Administrator>mysql -uroot -p
Enter password: ******
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
2、停止mysql服务
net stop mysql5----由于服务名是mysql5
3、修改my.ini文件
在安装路径下找到my.ini文件,我的是E:\Program Files\MySQL\MySQL Server 5.0
在【mysqld】下面添加一行:skip_grant_tables---跳过密码验证
4、登陆数据库修改密码
E:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -p
Enter password:                                                       ----这里可以直接敲回车
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.96-community-nt MySQL Community Edition (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> update user set password=password('mysql') where user='root';
ERROR 1046 (3D000): No database selected
mysql> use mysql                                                -----这里要选择mysql数据库
Database changed
mysql> update user set password=password('mysql') where user='root';  ----修改root用户密码
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> quit
Bye
E:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.96-community-nt MySQL Community Edition (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> update user set password=password('mysql') where user='root';
ERROR 1046 (3D000): No database selected
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
5、将my.ini中的skip_grant_tables删除
6、重启mysql5服务
C:\Users\Administrator>net start mysql5
MySQL5 服务正在启动 .
MySQL5 服务已经启动成功。
7、登陆数据库
C:\Users\Administrator>mysql -uroot -p
Enter password: *****                      ----输入刚刚设定的密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.96-community-nt MySQL Community Edition (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;                ----查看当前有哪些数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10271187/viewspace-1651544/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 单实例恢复至RAC
请登录后发表评论 登录
全部评论
DBA攻城狮

注册时间:2008-02-11

  • 博文量
    115
  • 访问量
    625472