zl程序教程

您现在的位置是:首页 >  其他

当前栏目

linuxmysql忘记密码的多种解决或Accessdeniedforuser'root'@'localhost'

密码密码 解决 root 多种 忘记 localhost linuxmysql
2023-06-13 09:14:11 时间
我的系统是ubuntu6.06,最近新装好的mysql在进入mysql工具时,总是有错误提示:
#mysql-uroot-p
Enterpassword:
ERROR1045(28000):Accessdeniedforuser"root"@"localhost"(usingpassword:NO)
使用网上介绍的方法修改root用户的密码:
#mysqladmin-uroot-ppassword"newpassword"
Enterpassword:
mysqladmin:connecttoserverat"localhost"failed
error:"Accessdeniedforuser"root"@"localhost"(usingpassword:YES)"
现在终于被我找到了解决方法,如下(请先测试方法三,谢谢!):
方法一:
#/etc/init.d/mysqlstop
#mysqld_safe--user=mysql--skip-grant-tables--skip-networking&
#mysql-urootmysql
mysql>UPDATEuserSETPassword=PASSWORD("newpassword")whereUSER="root";
mysql>FLUSHPRIVILEGES;
mysql>quit
#/etc/init.d/mysqlrestart
#mysql-uroot-p
Enterpassword:<输入新设的密码newpassword>
mysql>

方法二:
直接使用/etc/mysql/debian.cnf文件中[client]节提供的用户名和密码:
#mysql-udebian-sys-maint-p
Enterpassword:<输入[client]节的密码>
mysql>UPDATEuserSETPassword=PASSWORD("newpassword")whereUSER="root";
mysql>FLUSHPRIVILEGES;
mysql>quit
#mysql-uroot-p
Enterpassword:<输入新设的密码newpassword>
mysql>

方法三:
这种方法我没有进行过测试,因为我的root用户默认密码已经被我修改过了,那位有空测试一下,把结果告诉我,谢谢!!
#mysql-uroot-p
Enterpassword:<输入/etc/mysql/debian.cnf文件中[client]节提供的密码>
至此,困惑多时的问题解决了!