linux下 root 登录 MySQL 报错的问题
最近在centOS 7上,通过yum安装了mysql,安装成功后,使用root登录,出现了如下报错:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
mysql版本为:Ver 14.14 Distrib 5.7.10, for Linux(X86_64) using EditLine wrapper
然而实际上并没有进行过root密码设置(不知道是不是安装过程有被忽略的地方?)。
对此就各种寻找答案,大致有下面一些情况:
有说root的随机密码位于/root/.mysql_secret中,但是我根本没有/root/.mysql_secret文件。有文章表示
> ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using > password: NO) :表示没有生成root的临时密码 > > ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using > password: YES) :表示生成了root的临时密码。
有些资料说root的默认密码为空,经过确认那是以前的老版本,Mysql 5.6及以后版本出处于安全考虑,root密码已经不为空了。
最终找到对我来说有用的解决方案。
产生原因:
Now that the password MySQL had generated is expired, the problem is reduced to getting this password to work again (1) or generate a new one (2). This can be accomplished by running MySQL with the skip-grant-tables option which would make it ignore the access rights:
解决方法:
Stop your MySQL server.
Add skip-grant-tables at the end of the [mysqld] section of my.cnf file and save it.
Start MySQL server.
In terminal, typemysql -u root -pto get into MySQL command prompt.
In the command prompt, typeUSE mysql;to get into the mysql database where it keeps database users.
Type
UPDATE user SET password_expired = 'N' WHERE User = 'root';
to let MySQL know the password is not expired (1) or
UPDATE user SET authentication_string = PASSWORD('YourNewPassword'), password_expired = 'N' WHERE User = 'root';
附上链接:Unable to access MySQL after it automatically generated a temporary password
发布出来,供大家参考。
相关文章
MySQL存储过程之流程控制while,repeat,loop循环
这篇文章主要介绍了MySQL存储过程之流程控制while,repeat,loop循环,循环中的代码会运行特定的次数,或者是运行到特定条件成立时结束循环2022-07-07
mysql5.5 master-slave(Replication)配置方法
mysql5.5 master-slave(Replication)配置方法,需要的朋友可以参考下。2011-08-08
MySQL索引类型Normal、Unique和Full Text的讲解
今天小编就为大家分享一篇关于MySQL索引类型Normal、Unique和Full Text的讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧2019-03-03
ubuntu 16.04下mysql5.7.17开放远程3306端口
这篇文章主要介绍了ubuntu 16.04下mysql5.7.17开放远程3306端口的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-01-01
mysql 5.7.16 安装配置方法图文教程(ubuntu 16.04)
这篇文章主要为大家分享了ubuntu 16.04下mysql 5.7.16 安装配置方法图文教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-01-01
mysql使用mysqld_multi部署单机多实例的方法教程
这篇文章主要给大家介绍了关于mysql使用mysqld_multi部署单机多实例的相关资料,文中通过示例代码将实现的步骤一步步介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。2018-03-03


最新评论