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?
5 Answers
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, '', '');

- 999
- 2
- 15
- 29
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';
Update:
Try running the script from this answer:
Restoring Deleted 'Root' User and Password For MySQL
-
how did you log in in the console? how did you delete the account? – Ibu Jan 24 '13 at 23:43
-
I have the root account. It just deleted the root PRIVLEDGES. Is there a way to recover privledges? – mjkaufer Jan 25 '13 at 00:11
-
I logged in using phpmyadmin, but everything's f@cked up now. – mjkaufer Jan 25 '13 at 00:30
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

- 538,548
- 86
- 673
- 828
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.

- 239,200
- 50
- 490
- 574

- 9
- 1
This worked for me
- Download the relevent portable version of your xampp server
- 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.