3

I accidentally deleted the admin account, somehow, in my 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?

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
mjkaufer
  • 4,047
  • 5
  • 27
  • 55

5 Answers5

3

There is simple and easy way to solve this issue. you need to stop your mysql and goto mysql folder in your xampp folder. then run following command in your your command prompt.

c:\xampp\mysql> resetroot.bat

If you don't have that resetroot.bat then copy that content form here.

@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

USE 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, '', ''); 
Jenish Zinzuvadiya
  • 999
  • 2
  • 15
  • 29
2

From mysql documentation

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

Community
  • 1
  • 1
Ibu
  • 42,752
  • 13
  • 76
  • 103
1

The manual covers how to set or reset the root account's password if you delete (or forget) it:

http://dev.mysql.com/doc/refman/5.5/en/resetting-permissions.html

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
0

I accidentally deleted the root (admin) account on xampp and lost privileges. Finally, I found my way out:

  • Uninstall xampp
  • Install another version of xampp.

Bingo! Your root privileges are set again.

Note: you can't get your old databases of deleted root (admin) account back. Installing another version is necessary. Reinstalling the same version of xampp won't do a thing.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
0

This worked for me

  1. Download the relevent portable version of your xampp server
  2. Locate the xampp/mysql/data/mysql directory and replace it with the directory from protable version (zip file)

I think this resets mysql database. So this won't affect any other databases or your data.

El0din
  • 3,208
  • 3
  • 20
  • 31
Dum
  • 1,431
  • 2
  • 9
  • 23