欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

CentOS下安装mysql时忘记设置root密码致无法登录的解决方法

程序员文章站 2023-12-16 11:07:10
前言 昨天一天都是启动mysql时提示:the server quit without updating pid file,今天重装了mysql之后还是同样报错,然后恢复...

前言

昨天一天都是启动mysql时提示:the server quit without updating pid file,今天重装了mysql之后还是同样报错,然后恢复了一下/usr/my.cnf突然就可以启动了。(明明昨天/usr/my.cnf就是默认的,有个解决方法说改这个文件才改的)

然后现在就到没有设置root密码的问题了,搜了几个方法都不行,直到看到下面这个方法一才行。

解决方法一:

# /etc/init.d/mysql stop 
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 
# mysql -u root mysql 
mysql> update user set password=password('newpassword') where user='root'; 
mysql> flush privileges; 
mysql> quit 
# /etc/init.d/mysql restart 
# mysql -uroot -p 
enter password: <输入新设的密码newpassword> 
mysql> 

解决方法二:

直接使用/etc/mysql/debian.cnf文件中[client]节提供的用户名和密码:

# mysql -udebian-sys-maint -p 
enter password: <输入[client]节的密码> 
mysql> update user set password=password('newpassword') where user='root'; 
mysql> flush privileges; 
mysql> quit 
# mysql -uroot -p 
enter password: <输入新设的密码newpassword> 
mysql> 

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能有所帮助,如果有疑问大家可以留言交流。

上一篇:

下一篇: