Knowledgebase
Knowledgebase
Host is Not Allowed to Connect to MySQL Server
Posted by Will Kruss on 31 May 2016 10:29 PM

If you get the MySQL Error: Host ‘localhost’ is not allowed to connect to this MySQL server then read the article to fix it.

If your MySQL database has been corrupted or you don't have access to it any longer, you may get this error when you try to access MySQL server on Windows.

Host ‘localhost’ is not allowed to connect to this MySQL server.
Host ’127.0.0.1′ is not allowed to connect to this MySQL server.

Solution:

1. Stop MySQL service (from services.msc)

2. Create a text file in C:\ called “init.txt”. Paste the following code and save it.

GRANT ALL PRIVILEGES ON mysql.* TO root@localhost IDENTIFIED BY 'YourPassword!' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON mysql.* TO root@127.0.0.1 IDENTIFIED BY 'YourPassword!' WITH GRANT OPTION;

3. Open command prompt (cmd)

4. Go to MySQL bin directory on cmd.

Example: C:\Program Files\MySQL\MySQL Server 5.1\bin

 

5. Start MySQL service on cmd.

mysqld --init-file=C:\\init.txt

6. Close cmd and kill “mysqld.exe” from task manager.

7. Start MySQL service.

Now you should be able to connect MySQL via root user.

(3 vote(s))
Helpful
Not helpful