如何更改mysql的root密码 [英] How to change the mysql root password

查看:66
本文介绍了如何更改mysql的root密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在redhat linux上安装了MySQL服务器5.我无法以root用户身份登录,因此无法更改root用户密码.

I have installed MySQL server 5 on redhat linux. I can't login as root so I can't change the root password.

mysql -u root -p  
Enter password:  <blank>
ERROR 1045 (28000): Access denied for user 'root'@'localhost'
(using password: NO)

当我尝试像这样设置一个时:

When I try to set one like this:

mysqladmin -u root password 'newpass'

我得到一个错误:

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' 
(using password: NO)'

好像设置了root密码.

As if there is a root password set.

我还尝试使用(此处在 )

I have also tried resetting the password using (described here)

/sbin/service mysqld start --skip-grant-tables

然后制作:

mysql> UPDATE mysql.user SET Password=PASSWORD('newpass')     
->  WHERE User='root';  
ERROR 1142 (42000): UPDATE command denied to user ''@'localhost' for table 'user'

我什至卸载了mysql-server(使用yum),然后重新安装,但这没有帮助.

I even uninstalled mysql-server (using yum) and then reinstalled it but that did not help.

如何强制重置root密码?

How do I force reset the root password?

推荐答案

我删除了MySQL安装并删除了数据文件,然后重新安装了它.

I removed the MySQL installation and deleted the data files, and then reinstalled it.

然后,我可以设置root密码.将root密码设置为某种密码后.如果不知道,mysqladmin不会让您重置它.

Then I was able to set the root password. Once you set the root password to something. mysqladmin won't let you reset it if you don't know it.

要重置它,您必须对mysqld的执行方式拥有所有权,并向其提供一个初始化文件以更改root密码: https://dev.mysql.com/doc/refman/5.0 /en/reset-permissions.html

To reset it, you've got to have ownership over how mysqld is executed, and feed it an init file to change the root password: https://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

这篇关于如何更改mysql的root密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆