D:\Mystudy\mysql-8.0.12-winx64\mysql-8.0.12-winx64\bin>mysql
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)
(先将MySQL服务停掉)
1、在MySQL的bin目录下执行mysqld --skip-grant-tables,失效,仍然不能登录MySQL
发现在8.0后这个mysqld --skip-grant-tables跳过mysql的用户验证已经失效
在8.0后变为了在bin目录下执行mysqld --console --skip-grant-tables --shared-memory,跳过权限验证
2、另开一个cmd窗口,到bin下面执行mysql进入无密码登录页面
3、执行 use mysql
4、执行show tables;(分号不能丢),可以看到你需要账号的密码的各个表
5、执行修改密码操作:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
6、然后执行flush privileges;就好了
如果在修改密码的时候出现错误,如:The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
先执行flush privileges再执行修改密码的语句,再执行flush privileges