Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I issued a command of DROP USER 'root'@'localhost'; GRANT ALL PRIVILEGES ON . TO 'root'@'%';in PhpMyAdmin, immediately after the execution, I was forced out PhpMyAdmin,I got an error #1130 - Host 'localhost' is not allowed to connect to this MySQL server, how to resolve my problem?


locked by HopelessN00b Feb 20 '15 at 22:33

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

closed as off-topic by HopelessN00b Feb 20 '15 at 22:33

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions should demonstrate reasonable business information technology management practices. Questions that relate to unsupported hardware or software platforms or unmaintained environments may not be suitable for Server Fault - see the help center." – HopelessN00b
If this question can be reworded to fit the rules in the help center, please edit the question.

Do you have any important information in this database installation? – dlo Dec 10 '09 at 3:54
Yes, I have many tables. – Steven Dec 10 '09 at 13:56
This might be helpful:… – Ashwin A Aug 10 '12 at 12:18

Open up a terminal.

$ mysql -u root --host= -p<yourpassword>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 521
Server version: 5.1.38yes-debug yes

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE USER 'root'@'localhost' IDENTIFIED BY "<yourpassword>";
Query OK, 0 rows affected (0.22 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost;
Query OK, 0 rows affected (0.08 sec)

This should fix your problem ;).


mysql treats % and localhost differently. You need grant all privileges to 'root'@'localhost' as well.


On your server run mysql from command line:

mysql -u root -p -h localhost -P 3306

Then run this command in mysql shell:

>use mysql
>GRANT ALL ON *.* to root@'%' IDENTIFIED BY 'pass';

Have a nice time.

One sure fire way to bring yourself to the attention of the system is to post identical answers to questions - please don't. Also from a security point of view allowing root to access from anywhere isn't great either. – Iain Dec 18 '12 at 9:16

Combine dlo's answer with Darren Chamberlain's. The reason for this is that the special meaning that 'localhost' has in MySQL is that it signifies to use the local unix socket (mysql.sock) vs the TCP socket. This is why specifying as the host will get you in so that you can fix the situation; it signifies to the MySQL client to use the TCP socket.