恢复已删除的“root”; MySQL 的用户和密码
我不小心删除了在 OS X 上运行的 MAMP/MySQL 本地开发设置中的 root
用户。没有创建其他用户来返回 MySQL。
这是一场轻微的噩梦,没有root
似乎无法做任何事情。
发现这个:http://hack2live.blogspot.com/2009/04/restore -repair-reset-mysql-root.html 这似乎正是我所需要的。
我也不认为重新安装 MAMP 可以解决问题,因为我的很多粗略搜索都找到了尝试过但没有成功的人。
有谁知道 OSX 友好的方法来将 root
@ localhost
重新创建回 MAMP 的 MySQL?我基本上只是不知道 MySQL 位于 MAMP 中的哪个位置,也不知道如何在终端中执行正确的命令来尝试修复它。
更新
我尝试了以下几个选项来恢复根目录但无济于事,并决定恢复整个 MAMP 应用程序的备份。这样我就可以恢复 root 权限了,我可以打开 phpmyadmin 等。
I accidentally deleted the root
user on my local dev setup of MAMP/MySQL running on OS X. There are no other users created to get back into MySQL.
This is a mild nightmare can't seem to do anything without root
.
Found this: http://hack2live.blogspot.com/2009/04/restore-repair-reset-mysql-root.html which seems like exactly what I need.
I also don't think a reinstall of MAMP will do the trick, as a lot of my cursory searches yielded people who had tried without success.
Does anyone know of an OSX friendly way to recreate root
@ localhost
back into MAMP's MySQL? I basically just don't know where MySQL is living in MAMP or how to execute the correct commands in terminal to try and fix it.
Update
I tried several options below to restore root to no avail and decided to restore a backup of the entire MAMP application. So I've got root back, I can open phpmyadmin, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
我有一个快速而肮脏的方法
,找一个具有系统管理员权限的人,然后执行以下操作:
将“skip-grant-tables”添加到 my.cnf 的 [mysqld] 部分
重新启动 mysql
不带密码输入 mysql 并按 Enter
运行此:
从 mysql 退出
从 [mysqld] 部分下的 my.cnf 中删除“skip-grant-tables”
restart mysql
这应该就是全部了!
I have a quick and dirty way
Get someone with SysAdmin rights and do the following:
Add 'skip-grant-tables' to my.cnf under the [mysqld] section
restart mysql
type mysql with no password and hit enter
Run This:
exit from mysql
remove 'skip-grant-tables' from my.cnf under the [mysqld] section
restart mysql
That should be all!
http://hack2live.blogspot.com 的翻译版本/2009/04/restore-repair-reset-mysql-root.html - 适用于 OS X。
打开 TextEdit.app 并在格式 -> 中选择“制作纯文本”。
将以下内容剪切并粘贴到 TextEdit 中,并将其保存到您的 HOME 文件夹中,名称为
restore_root_privileges.sql
保存并退出 TextEdit.app。
停止 mysqld 服务器。 如何执行此操作取决于您使用的 MySQL 安装方式。
您的系统首选项中可能有一个 PreferencePane。如果没有,您必须查阅 MySQL 安装的文档。
打开 Terminal.app(应用程序/实用程序)
输入以下命令:
像平常一样启动 MySQL 服务器,例如从 PreferencePanes 启动。
在 Terminal.app 中:输入以下内容:
就这样。 没有任何保证。如果做错什么,您可能会丢失所有数据。 首先备份你的mysql文件。
如果你得到类似的信息:
那就意味着你的安装不正确,你应该找到你的mysql二进制文件在哪里,并且需要将目录输入到你的PATH变量中。
The translated version of http://hack2live.blogspot.com/2009/04/restore-repair-reset-mysql-root.html - for OS X.
Open TextEdit.app and select in Format -> "Make plain text".
Cut and paste the following into TextEdit and save it into your HOME folder with name
restore_root_privileges.sql
Save and quit TextEdit.app.
Stop you mysqld server. How to do this, depends on what installation did you use for MySQL.
You probably have an PreferencePane in your system preferences. If not, you must consult the docs for your MySQL installation.
Open Terminal.app (Applications/Utilities)
Enter the following commands:
Start your MySQL server as usually, e.g. from PreferencePanes.
In the Terminal.app: enter the following:
That's all. Without any warranty. You can loose all you data if do something wrong. Backup first your mysql files.
If you got something like:
thats mean, than your installation is incorrect and you should find where are your mysql binaries, and need enter the directory into you PATH variable.
我刚刚遇到了同样的问题。我在 Windows 7 上使用 Xammp。我不小心删除了 phpmyadmin 中的 root 用户。
看来我能够通过简单的方法解决问题,如下所示:
在 xammp 控制中停止 apache 和 mysql
转到 .../xammp/mysql
您将看到文件“resetroot”。运行此文件
此应用程序完成后,重新启动 mysql 和 apache
转到 phpmyadmin,您将看到 root 用户已恢复
现在您可以再次访问所有数据库
I just got the same - problem. I am using Xammp on Windows 7. I accidently deleted a root user in phpmyadmin.
It appears I was able to fix the problem in easy route like this:
Stop the apache and mysql in xammp control
Go to .../xammp/mysql
You will see the file "resetroot". Run this file
After this application is finished, restart your mysql and apache
Go to phpmyadmin and you will see the root user restored
Now you can access all your databases again
MySQL 5.7已将Password字段替换为authentication_string(在mysql.user表中);所以这对我有用。
MySQL 5.7 had replaced Password field with authentication_string (in mysql.user table); so this worked for me.
使用映射。我犯了一个明显常见的错误:在创建另一个用户时删除 root 用户,我被锁定了!
所以我找到了这篇文章并尝试按照说明进行操作,但是......
我收到了以下错误:
-bash: mysql: 尝试执行命令 mysql 命令时找不到命令,后来我收到此错误
当尝试为 root 用户设置正确的权限并在 shell 中的 mysql 中对该用户执行任何操作时,DELETE 命令拒绝对表“user”的用户“@”localhost”执行任何操作。
所以在我可以使用 eric 和 rolando 发布的命令之前(谢谢你们)
这就是我所做的
我需要正确启动 mysqld 所以
我必须执行以下操作
<块引用>
ps 辅助 | grep mysql
and stop the mamp interface application aswell..
找到的任何 mysql 进程
<块引用>
kill -9 [pid]
do make sure no mysql process are running before you go any further.
这个commnad将启动mysld而不要求输入密码(有点像安全模式)
我尝试使用 my.cnf 文件但无法使其工作。
(如果提示输入密码,只需按回车键)
然后执行 eric 和 rolando 发布的命令,这次我没有收到任何错误“DELETE command returned to user” ''@'localhost' for table 'user'" 如果这样做,则说明您没有正确启动 mysqld
然后停止 mysqld 服务:
然后像往常一样使用 gui 重新启动 mamp
,一切都开始像以前一样工作......我松了一口气!
2个小时的恐慌和控制台的反复试验...宝贵的经验教训..
如果我弄乱了任何命令或解释(这可能是我在写这篇文章时回溯我的步骤时的情况,请让我知道。我很乐意更新帖子,
最后不要这样做!
using mamp. I made the apparently common mistake of deleting the root user when creating another user, I was locked out!
so I found this post and tried to follow the directions but...
I was getting this errores:
-bash: mysql: command not found when trying to execute the command mysql commands and later I was getting this error
DELETE command denied to user ''@'localhost' for table 'user' when tring to set properly privileges to the root user and do anything with that user once mysql in shell.
so before I could use the commands eric and rolando posted (thank you guys for that)
this is what I did
I need to start mysqld properly so
I had to do the following
and stop the mamp interface application aswell..
do make sure no mysql process are running before you go any further.
this commnad will start mysld without asking for a password (sort of like in safemode)
I tried with my.cnf file but couldn't get it to work.
(if prompted for a password just hit enter)
then execute the commands eric and rolando posted, this time I didnt get any error "DELETE command denied to user ''@'localhost' for table 'user'" if you do, you didn't start mysqld properly
then stop the mysqld service:
then restarted mamp as usual with the gui
and all started to work again as it was before... I was so relieved!!!
2 hours of panic and trial and error with the console... valuable lessons learned..
If I messed up any of the commands or the explanation (which could be the case as I was tracing my steps back as writing this post please let me know. I'd be happy to update the post.
lastly don't give. it can be done!!
我昨天做了完全相同的事情,对 mac 和 sql server 都是新手。我不小心删除了 root 用户,因为我在尝试设置新用户和密码时按了“权限”中的错误按钮。
我在这台计算机上没有任何有用的工作,因此不担心删除我的网站。
现在,一旦 MAMP 启动,我就可以通过启动页面上的链接访问 phpMyAdmin。
I did exactly the same thing yesterday, being new to macs and the sql server. I accidentally deleted the root user because I pressed the wrong button in Privileges whilst trying to set up a new user and password.
I did not have any work of any use on this computer so was not worried about deleting my websites.
I now have access to phpMyAdmin through the link on the startup page once MAMP is booted.
只是想贡献一下我是如何解决这个问题的。如果您不小心删除了 MAMP PRO 中的 root 用户,并且正在使用带有 Time Machine 备份的 OSX。只需在查找器中转到此文件夹:
/Library/Application Support/appsolute/
然后从顶部菜单栏中“进入 Time Machine”并恢复 MAMP PRO 文件夹的最新备份。为我省去了很多麻烦。
Just wanted to contribute how I resolved this. If you accidentally deleted the root user in MAMP PRO and are using OSX with Time Machine backups. Simply go to this folder in finder:
/Library/Application Support/appsolute/
Then 'Enter Time Machine' from the top menu bar and restore a recent backup of the MAMP PRO folder. Saved a lot of hassle for me.
好的,停止运行 MySQL,然后打开它附带的安装文件。应该有一个名为resetroot.bat 的bat 文件。运行它,你的问题就会消失。
Ok, stop running your MySQL, and open up the installation files it came with. There should be a bat file named resetroot.bat. Run it and your problem will be gone.
在 CentOS 6 上为我工作。我不得不取出 Create_tablespace_priv = 'y' 因为我的版本会发出嘎嘎声,否则一切都很好。
Worked for me on CentOS 6. I had to take out Create_tablespace_priv = 'y' because my version squawked otherwise all good.