当前位置: 移动技术网 > IT编程>数据库>Mysql > linux下 root 登录 MySQL 报错的问题

linux下 root 登录 MySQL 报错的问题

2017年12月12日  | 移动技术网IT编程  | 我要评论

豪斯医生第八季,关于袁鹰的资料,储物瓶

最近在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';

附上链接:

发布出来,供大家参考。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网