MySQL Host '::1' or '127.0.0.1' is not allowed to connect to this MySQL server

The variable skip_name_resolve gives better performance because the server does not try to resolve the names of the connecting clients or look for them every time in the host name cache (even localhost is resolved/searched), but the manual states that config also limits the @localhost connections. The solution is to copy the @localhost users with @127.0.0.1, like this:

CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'root-password';
CREATE USER 'root'@'::1' IDENTIFIED BY 'root-password';
FLUSH PRIVILEGES;

where ::1 is localhost for IPv6 addressing. This way we keep the root and local accounts limited to the local server; using '%' open the potential clients to the world, and we don't want that. Disabling skip_name_resolve also requires the server having an accesible and fast DNS resolver to minimize latency.

I noted that I can connect with a local phpmyadmin even if the user has @localhost; this is because phpmyadmin connects thru a local unix socket, a special type of file used to communicate between processes, and does not need networking.

EDIT: As @Francisco R noted, the new root users also should have full access to all databases by issuing the following commands:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1'
GRANT ALL PRIVILEGES ON *.* TO 'root'@'::1'
FLUSH PRIVILEGES

I had the same message after a fresh installation with the no-install zip and solved it as follows. Perhaps this could have been a solution for your problem too:

  1. Stop the MySQL server or service.
  2. Open a Command Prompt window with administrative rights and go to the bin folder in the MySQL install directory.
  3. Start MySQL with skip-grants-table and don't forget your config file:

mysqld --defaults-file=[filename] --skip-grant-tables

  1. Open another Command Prompt window and go to the bin folder again.
  2. Now you can login:

mysql -u root -p

  1. Show the users with:

SELECT user, host FROM mysql.user;

  1. Verify there is one 'root' with host 'localhost'.
  2. Change the host:

UPDATE mysql.user SET host='%' WHERE user='root';

  1. Exit the mysql program and close the Command Prompt window.
  2. Type Ctrl-C in the other Command Prompt window to stop the server, then close the Command Prompt Window.
  3. Start MySQL as you normally would and verify that you can login.

Ok i Fixed...

I've comment "skip_name_resolve" in my.ini and everything is back to work.. i really don't know why because this record was in my.ini also yesterday..last week.. last month..

Tags:

Mysql