简体   繁体   中英

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

I have a strange issue on a web server (Windows Server 2012) with MySQL 5.7.16. I can't connect anymore to mysql server, I don't know why.

If I type mysql -uroot -ppassword appear an error

ERROR 1130 <HY000>: Host '::1' is not allowed to connect to this MySQL server or
ERROR 1130 <HY000>: Host '127.0.0.1' is not allowed to connect to this MySQL server

I tried to use another user with all privileges and I've seen that in host there is only localhost (not 127.0.0.1 or ::1)

How can I login with root@localhost and not with root@127.0.0.1? It's very frustrating... Every account trying to use @127.0.0.1 or @::1 but there exist only localhost in host and I can't change it.

If I type mysql -uroot -ppassword I see
ERROR 1130 <HY000>: Host '127.0.0.1' is not allowed to connect to this MySQL server

Same if I type mysql -uroot -ppassword -h localhost or anything else

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..

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.

I came here looking for a solution using Local by flywheel for wordpress development to the same problem, BUT, in a linux machine.

Just if someone faces the same problem, the solution listed here works.

Just comment skip_name_resolve in the file conf/mysql/my.cnf.hbs under the file tree created by Local

Thanks!

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.

确保在创建用户时指定 % 作为主机名,否则用户将只能从本地主机连接。

Looks that you need to modify your hosts file. C:\\Windows\\System32\\Drivers\\etc\\hosts

just add the line and save it, (to be able to edit and save you may need to open it as administrator)

127.0.0.1 localhost

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM