如何重置mysql root密码?
我的 phpmyadmin 有一个小问题,事实上我不小心删除了多个用户帐户。 因为不可能在没有错误的情况下连接:
# 1045 - Access denied for user 'root' @ 'localhost' (using password: NO)
我之前在网上搜索过一点,甚至技术:
UPDATE mysql.user SET Password = PASSWORD ('') WHERE User = 'root';
FLUSH PRIVILEGES;
不起作用,或者我不明白它是如何工作的。
我使用的是 FreeBSD 8.1,我的 PhpMyadmin 版本是 2.11。
预先感谢您的答复。
I have a little problem with my phpmyadmin, in fact I accidentally delete multiple user accounts.
Since it is impossible to connect without the error:
# 1045 - Access denied for user 'root' @ 'localhost' (using password: NO)
I have search a little on the net before, and even the technic:
UPDATE mysql.user SET Password = PASSWORD ('') WHERE User = 'root';
FLUSH PRIVILEGES;
does not work, or I didn't understood how it worked.
I'm on FreeBSD 8.1, my version of PhpMyadmin is 2.11.
Thank you in advance for your answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我在这里总结了我的解决方案: http://snippets.dzone.com/posts/show/13267
I summarised my solution here: http://snippets.dzone.com/posts/show/13267
对于 mysql 5.7.16 或更高版本,我发现 this (来自 mysql.com)作为可行的解决方案。以下是与以前的旧版本相比的一些不同之处
1) 我使用以下命令在安全模式下运行 mysql,根据其他一些参考文献,这些参考资料实际上对我来说效果很好(mysql 5.7.16 ubuntu 16.04)。
2) 下面的更新 stmt 不适用于更高版本(即 5.7 及更高版本),
请使用下面的 5.7.6 及更高版本
或用户下面的 5.7.5 或更早版本。
For mysql 5.7.16 or later I found this (from mysql.com) to be the working solution. Below are some points which are different compared to previous older versions
1) I used the below command to run mysql in safe mode as per some other references which actually worked fine for me (mysql 5.7.16 ubuntu 16.04).
2) The below update stmt is NOT working for later version (ie. 5.7 and above)
INSTEAD use below for 5.7.6 and later
OR user below for 5.7.5 or earlier versions.
我正在使用 MySQL Server 8,这就是我解决这个问题的方法。
创建一个文件并相应命名。我将其命名为reset.txt。将以下内容放入文件中,但更改 MyNewPass。这将是您的新 SQL 密码
停止我的 SQL 服务器(转到服务并搜索 MYSQL 并右键单击它并停止)
现在在 My SQLserver 目录的 bin 文件夹中打开一个 cmd。就我而言是
执行以下命令。
注意:我的reset.txt文件位于c盘中。给出正确的路径。检查 my.ini 文件是否在目录中。就我而言,它是在
最后,重新启动 SQL Server。检查您的新密码。
I am Using MySQL Server 8 and this is how I solved this problem.
create a file and name it accordingly. I've named it as reset.txt. put below content in the file but change MyNewPass. This will be your new SQL password
Stop my SQL server (Go to services and search MYSQL and right-click on it and stop )
Now open a cmd in your bin folder of My SQLserver directory. in my case it's
execute the following command.
NOTE: my reset.txt file is in the c drive. Give the correct path. Check my.ini file is in the directory. In my case, it is in
Finally, restart the SQL Server. Check with your new password.
请按照以下链接中的说明重置 root 密码。您必须从 mysql 外部执行此操作。
重置 MySql 密码
忘记 MySQL 密码可能会让您非常头疼。您可以按照以下一些简单步骤在 Windows 下恢复 MySql 密码
停止MySql
在继续之前,您必须停止MySql 服务。在Windows 环境中,转到“任务管理器”并在“服务”选项卡下找到MySQL 并停止它。
编写 Sql 来更改密码
您所需要做的就是创建一个文本文件并将以下两行放入其中。 UPDATE mysql.user SET 密码=PASSWORD('MyNewPass') WHERE User='root';同花顺特权;将其保存在 C:\ 驱动器下并命名为“mysql-init.txt”
是时候自己重启 MySQL 了。
现在是时候重新启动之前停止过的 MySQL,但这次是从命令行启动。 C:> C:\mysql\bin\mysqld-nt --init-file=C:\mysql-init.txt
收尾啦!
现在您可以使用新密码登录。完成后,删除您在上一阶段创建的文件。
还有一个链接(http://kaziprogrammingblog.osinweb.com/article/showarticle /Resetting-MySql-Password),我在其中解释了同样的事情。
希望这会有所帮助..:)
Please follow the instruction from the below link to reset your root password.You have to do it from outside mysql.
Resetting MySql Password
Forgetting your MySQL password can be a real headache for you.Here are some easy steps that you can follow to recover MySql password under Windows
Stop MySql
You have to stop MySql service before you proceed.In Windows environment, go to 'Task Manager' and Under 'Service' tab find MySQL and stop it.
Write Sql to change your password
All you need to do is to create a text file and put the below two lines into that. UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root'; FLUSH PRIVILEGES; Save it under C:\ drive and give it a name 'mysql-init.txt'
Time to restart MySQL by your own.
Now it's time to restart your MySQl which you stopped in before but this time from command line. C:> C:\mysql\bin\mysqld-nt --init-file=C:\mysql-init.txt
Finishing up!
Now you can log in with your new password. When you finish remove the file that you created in the previous stage.
Also there is a link (http://kaziprogrammingblog.osinweb.com/article/showarticle/Resetting-MySql-Password) where I have explained the same thing.
Hope this will help..:)
Windows 上 XAMPP 的答案:
完成!
请注意,mysql root 用户密码不必与 phpmyadmin 的密码相同。
Answer for XAMPP on Windows:
DONE!
Be awared that mysql root user password does not have to be the same as password for phpmyadmin.
这是我所做的并且有效:
安装(rpm 安装)后,执行
vi /etc/my.cnf
。这将为您提供设置
datadir
的路径。对我来说是datadir=/var/lib/mysql
。在那里添加一行
user=root
,并删除datadir
路径中的所有内容:rm -rf /var/lib/mysql/*
.现在输入命令:
mysqld --initialize
。在某个位置生成临时密码。为此:
grep“临时密码”/var/log/*
。您将看到一行内容:
/var/log/mysqld.log:2018-05-01T15:13:47.937449Z 5 [Note] [MY-010454] [Server] 为 root@localhost 生成临时密码: &uosjoGfi9:K< /代码>。所以对我来说
&uosjoGfi9:K
是我的临时密码。现在执行
mysql -u root -p
。粘贴您从上面获得的临时密码。您将处于 mysql cli 模式。现在做:
mysql>使用mysql;
系统会要求您重置密码:
错误 1820 (HY000):在执行此语句之前,您必须使用 ALTER USER 语句重置密码。
运行您的 ALTER 命令:
mysql>更改由“MyNewPswd”标识的用户“root”@“localhost”;
你就完成了。
here is what I did and it worked:
After you install (rpm installation), do a
vi /etc/my.cnf
.This will give you a path where your
datadir
is set. For me it wasdatadir=/var/lib/mysql
.Add a line there
user=root
, and remove all the content inside thedatadir
path:rm -rf /var/lib/mysql/*
.Now hit the command:
mysqld --initialize
.A temporary password is generated at a location. For this:
grep "A temporary password" /var/log/*
.You will get a line that says:
/var/log/mysqld.log:2018-05-01T15:13:47.937449Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: &uosjoGfi9:K
. So for me&uosjoGfi9:K
was my temporary password.Now do a
mysql -u root -p
. Paste your temporary password from what you got from above.You will be in your mysql cli mode. Now do:
mysql> use mysql;
You will be asked to reset your password:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
Run your ALTER command:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPswd';
And you are done.
就我而言,它是一个令人沮丧的 Windows Server 安装(iis/php/mysql),所以这就是我所做的:
第 1 部分:删除旧的 MYSQL:
注意:如果您已经有数据,则应该备份它!
步骤1
从控制面板卸载 MySQL。 (你应该知道怎么做)
第2步
以管理员身份运行命令提示符并执行以下命令来停止和删除 MySQL 服务。
步骤3
删除这些文件夹:
如果存在:
第 2 部分:安装 MYSQL
从 https://dev 下载安装程序。 mysql.com/downloads/installer/ 并安装
-MySQL Server 8.0.23
以管理员身份打开cmd并转到
c:\Program Files\MySQL\MySQL Server 8.0\bin\
现在运行
启动服务(在运行面板中键入 services.msc)
现在回到控制台运行:
就是这样
in my case its a frustrating Windows Server installation (iis/php/mysql) so this is what i did:
PART 1: remove the old MYSQL :
NOTE: if you already have data you should back it up!
Step 1
Uninstall MySQL from Control Panel. (you should know how to do this)
Step 2
Run Command Prompt as Admini and execute the following commands to stop and remove MySQL service.
Step 3
Delete these folders:
And if it exists:
PART 2: Install MYSQL
Download installer from https://dev.mysql.com/downloads/installer/ and install
-MySQL Server 8.0.23
open cmd as admin and go to
c:\Program Files\MySQL\MySQL Server 8.0\bin\
run
now start the service (type services.msc in run panel)
now back to console run:
that's it
mysql80:
mysql80: