很多情况数据库很久没有使用,偶尔打开会出现一系列错误,例如1045错误即是
mysql ERROR 1045 : Access denied for user‘root’@localhost(using password:YES)
即使密码是对的也难以登录到数据库,查阅很多资料找到了合适的方法:
编辑mysql配置文件my.ini,在[mysqld]这个条目下加入
skip-grant-tables
保存退出后重启mysql
1.点击“开始”->“运行”(快捷键Win+R)。
2.启动:输入 net stop mysql
3.停止:输入 net start mysql
这时候在cmd里面输入mysql -u root -p就可以不用密码登录了,出现password:的时候直接回车可以进入,不会出现ERROR 1045 (28000),但很多操作都会受限制,因为我们不能grant(没有权限)。按下面的流程走(红色部分为输入部分,粉红色的是执行后显示的代码不用输入):
1.进入mysql数据库:
mysql> use
mysql;
Database changed
2.给root用户设置新密码,蓝色部分自己输入:
mysql> update user set password=password("新密码") where user="root";
Query OK, 1 rows affected (0.01 sec)
Rows
matched: 1 Changed: 1 Warnings: 0
3.刷新数据库
mysql> flush
privileges;
Query OK, 0
rows affected (0.00 sec)
4.退出mysql:
mysql> quit
这个时候MySql就可以正常登录了!