[英]I accidentally deleted the admin account in my phpMyAdmin. How can I re-give privileges to root@localhost?
I accidentally deleted the admin account, somehow, in my phpMyAdmin.我不小心删除了我的 phpMyAdmin 中的管理员帐户。 Now, I can't do anything at all.
现在,我什么也做不了。 I can access the console, however, and it lets me log in. How can I re-give privileges to root@localhost?
但是,我可以访问控制台,并且它可以让我登录。如何重新授予 root@localhost 权限?
There is simple and easy way to solve this issue.有一种简单易行的方法可以解决这个问题。 you need to stop your mysql and goto mysql folder in your xampp folder.
您需要停止 mysql 并转到 xampp 文件夹中的 mysql 文件夹。 then run following command in your your command prompt.
然后在您的命令提示符中运行以下命令。
c:\\xampp\\mysql> resetroot.bat
c:\\xampp\\mysql> resetroot.bat
If you don't have that resetroot.bat then copy that content form here.如果您没有那个 resetroot.bat,请在此处复制该内容表单。
@echo off
echo USE mysql; >resetroot.sql
echo. >>resetroot.sql
echo REPLACE INTO user VALUES ('localhost', 'root', '', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', 0, 0, 0, 0, '', ''); >>resetroot.sql
echo REPLACE INTO user VALUES ('127.0.0.1', 'root', '', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', 0, 0, 0, 0, '', ''); >>resetroot.sql
echo REPLACE INTO user VALUES ('localhost', 'pma', '', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', '', '', '', '', 0, 0, 0, 0, '', ''); >>resetroot.sql
bin\mysqld.exe --no-defaults --bind-address=127.0.0.1 --bootstrap --console --standalone <resetroot.sql >nul
del resetroot.sql
echo.
echo Passwoerter fuer Benutzer "root" und "pma" wurden geloescht.
echo Passwords for user "root" and "pma" were deleted.
echo.
pause
Use this file as resetroot.sql将此文件用作 resetroot.sql
USE mysql;使用 mysql;
REPLACE INTO user VALUES ('localhost', 'root', '', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', 0, 0, 0, 0, '', '');
REPLACE INTO user VALUES ('127.0.0.1', 'root', '', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', 0, 0, 0, 0, '', '');
REPLACE INTO user VALUES ('localhost', 'pma', '', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', '', '', '', '', 0, 0, 0, 0, '', '');
From mysql documentation来自 mysql 文档
Creating account, and giving priviledges创建帐户并授予权限
mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
-> WITH GRANT OPTION;
mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
-> WITH GRANT OPTION;
mysql> CREATE USER 'admin'@'localhost';
mysql> GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';
mysql> CREATE USER 'dummy'@'localhost';
Update :更新:
Try running the script from this answer:尝试从这个答案运行脚本:
Restoring Deleted 'Root' User and Password For MySQL为 MySQL 恢复已删除的“root”用户和密码
The manual covers how to set or reset the root account's password if you delete (or forget) it:该手册介绍了在删除(或忘记)root 帐户密码时如何设置或重置它:
http://dev.mysql.com/doc/refman/5.5/en/resetting-permissions.html http://dev.mysql.com/doc/refman/5.5/en/resetting-permissions.html
I accidentally deleted the root (admin) account on xampp and lost privileges.我不小心删除了 xampp 上的 root (admin) 帐户并丢失了权限。 Finally, I found my way out:
最后,我找到了出路:
Bingo!答对了! Your root privileges are set again.
您的 root 权限将再次设置。
Note: you can't get your old databases of deleted root (admin) account back.注意:您无法恢复已删除的 root (admin) 帐户的旧数据库。 Installing another version is necessary.
需要安装另一个版本。 Reinstalling the same version of xampp won't do a thing.
重新安装相同版本的 xampp 不会做任何事情。
This worked for me这对我有用
xampp/mysql/data/mysql
directory and replace it with the directory from protable version (zip file)xampp/mysql/data/mysql
目录并将其替换为 protable 版本(zip 文件)中的目录I think this resets mysql
database.我认为这会重置
mysql
数据库。 So this won't affect any other databases or your data.所以这不会影响任何其他数据库或您的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.