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

查看:35
本文介绍了如何更改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)

当我尝试这样设置时:

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.

我也尝试使用(描述了here)

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 的执行方式拥有所有权,并向其提供一个 init 文件以更改 root 密码:https://dev.mysql.com/doc/refman/5.0/en/resetting-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天全站免登陆