问题描述
自己一觉醒来数据库服务失效,密码输入正确但也无法登陆,准备重置数据库密码,在进行步骤
mysqld --initialize --console
初始化数据库密码,输入密码后仍然无法进入数据库并报错
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
问题解决
1.关闭数据库服务:
net stop mysql
2.管理员权限打开cmd(注意一定要是管理员权限)
在终端中进入到你的MySQL安装目录的bin文件目录下
MySQL 8.x无权限登陆:
mysqld --console --skip-grant-tables --shared-memory
MySQL 5.x无权限登陆:
mysqld --skip-grant-tables
3.新建一个终端窗口(管理员运行) (-p的密码空白,进行免密登录)
mysql -u root -p
登陆成功后执行:
alter user 'root'@'localhost' identified by '新的密码';
3.1这里可能会出现权限不够的问题:
ERROR 1290 (HY000): The MySQL server is running with the
–skip-grant-tables option so it cannot execute this statement
刷新权限解决:
flush privileges;
刷新完成后继续执行修改新的密码指令
alter user 'root'@'localhost' identified by '新的密码';
4.关闭所有的终端窗口重新MySQL服务:
net start mysql
5.登陆MySQL
mysql -uroot -p 刚设置的密码