数据库 
首页 > 数据库 > 浏览文章

linux下 root 登录 MySQL 报错的问题

(编辑:jimmy 日期: 2024/9/21 浏览:3 次 )

最近在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 Workbench的使用方法(图文)
下一篇:MySQL批量插入数据脚本
一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap