简体   繁体   English

我不小心删除了我的 phpMyAdmin 中的管理员帐户。 如何重新授予 root@localhost 权限?

[英]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';

Adding User添加用户

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:最后,我找到了出路:

  • Uninstall xampp卸载 xampp
  • Install another version of xampp.安装另一个版本的 xampp。

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这对我有用

  1. Download the relevent protable version of your xampp server下载您的 xampp 服务器的相关可移植版本
  2. Locate the 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.

相关问题 如何在MySQL中授予root @ localhost的所有特权? - How can I grant all privileges to root@localhost in MySQL? 如何在 MySQL 中以 root@localhost 权限运行? - How can I run with root@localhost privileges in MySQL? 我为 phpadmin 和/或 mysql 搞砸了我的 root@localhost。 如何重置密码? - I messed up my root@localhost for phpadmin and/or mysql. How can I reset the passwords? 在PHPMyAdmin(XAMPP)的root @ localhost上丢失了全局特权 - Lost Global Privileges on root@localhost in PHPMyAdmin (XAMPP) 我无法使用 MySQL shell 连接 root@localhost - I can't use MySQL shell to connect root@localhost 在管理面板中意外删除了产品,如何将其找回? - Accidentally deleted a product in the admin panel,how can I get it back? 意外删除了管理员,如何通过phpmyadmin mysql将其重新添加 - Deleted admin accidentally how to add it back via phpmyadmin mysql MySQL无法访问root@localhost - MySQL Can't Access root@localhost 在ubuntu上安装phpmyadmin后,我忘记了phpmyadmin的用户名和密码。 我将如何再次恢复这些? - After installation of phpmyadmin on ubuntu I forgot the username and password of phpmyadmin. How will I able to recover these again? Mariadb 上 Ubuntu 我代表 CURRENT_USER 的用户是 root@% 而不是 root@localhost - Mariadb on Ubuntu the user I'm for CURRENT_USER is root@% and not root@localhost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM