linux下当我输入mysql -uroot -p 之后让我输入密码
输入完密码后 报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor:yes)
分析了一下报错的原因是密码错误引起的,我这边是忘记了密码(所以下面的操作是重置密码步骤)
- 修改 /etc/my.cnf 文件,在文件中添加skip-grant-tables(如图),
- 保存之后 重启mysql 命令 service mysqld restart
- 重启完成后看一下mysql的状态 命令service mysqld status
- 启动完成后,直接在命令行输入 mysql 会直接进入了mysql
- 进入之后,下面开始更改密码 命令update user set password=password("新密码") where user="root";
- 发现报错ERROR 1046 (3D000): No database selected ,报错的原因是没有选中database
- 执行 use mysql;
- 进入mysql库之后 用update user set password=password("新密码") where user="root";修改密码
- 发现报错ERROR 1054 (42S22): Unknown column 'password' in 'field list'
- 可以看出来是因为user表中没有password这个列,网上查了之后发现mysql5.7之后password这个列变成了authentication_string
- 直接执行命令,更改密码 命令 update user set authentication_string=password("Hqp_bigdata1") where user="root";
- 密码修改成功
- 然后执行flush privileges
- 推出mysql之后,修改/etc/my.cnf 把skip-grant-tables注释了
- 然后重启mysql 用刚才设置的密码登陆