MySQL 之1045错误

在终端中输入mysql -uroot -p后输入密码,出现1045错误如下:
ERROR 1045(28000): Access denied for user 'root'@'localhost'(using password)

解决方法:

  • 先找到mysql bin目录下的my.ini文件,在[mysql]下面加上 skip-grant-tables 用于跳过密码
  • 重启服务器
    net stop mysql
    net start mysql
  • 输入mysql -uroot -p 回车,不用输入密码回车
    mysql > use mysql;
  • 修改密码:
    mysql > set password for 'root'@'localhost'=password('123456');
    在网上看使用下面语句,但是我报错
    ERROR 1054 (42S22): Unknown column 'password' in 'field list'
    又查了查可能是版本问题,然后我使用下面语句成功了
    mysql> update user set authentication_string=password('123456') where user='root';
  • 刷新数据库
    mysql > flush privilegs;
  • 退出
    mysql > quit;
  • 修改 my.ini 注释掉skip-grant-tables保存退出
  • 重启服务器
    net stop mysql
    net start mysql
  • 再输入mysql -uroot -p就能进入mysql
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容