简体   繁体   English

MySQL 主机 '::1' 或 '127.0.0.1' 不允许连接到此 MySQL 服务器

[英]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.我在装有 MySQL 5.7.16 的 Web 服务器(Windows Server 2012)上遇到了一个奇怪的问题。 I can't connect anymore to mysql server, I don't know why.我无法再连接到 mysql 服务器,我不知道为什么。

If I type mysql -uroot -ppassword appear an error如果我输入 mysql -uroot -ppassword 出现错误

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)我试图使用具有所有权限的另一个用户,我已经看到在主机中只有本地主机(不是 127.0.0.1 或 ::1)

How can I login with root@localhost and not with root@127.0.0.1?如何使用 root@localhost 而不是 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.这非常令人沮丧......每个帐户都试图使用@127.0.0.1 或@::1 但主机中只存在本地主机,我无法更改它。

If I type mysql -uroot -ppassword I see如果我输入 mysql -uroot -ppassword 我看到
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如果我输入 mysql -uroot -ppassword -h localhost 或其他任何内容,则相同

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..我在 my.ini 中评论了“skip_name_resolve”,一切都恢复正常了..我真的不知道为什么,因为这条记录也在昨天..上周..上个月..

I had the same message after a fresh installation with the no-install zip and solved it as follows.在使用 no-install zip 进行全新安装后,我收到了相同的消息,并按如下方式解决了这个问题。 Perhaps this could have been a solution for your problem too:也许这也可以解决您的问题:

  1. Stop the MySQL server or service.停止 MySQL 服务器或服务。
  2. Open a Command Prompt window with administrative rights and go to the bin folder in the MySQL install directory.打开具有管理权限的命令提示符窗口,然后转到 MySQL 安装目录中的 bin 文件夹。
  3. Start MySQL with skip-grants-table and don't forget your config file:使用 skip-grants-table 启动 MySQL,不要忘记你的配置文件:

mysqld --defaults-file=[filename] --skip-grant-tables mysqld --defaults-file=[文件名] --skip-grant-tables

  1. Open another Command Prompt window and go to the bin folder again.打开另一个命令提示符窗口并再次转到 bin 文件夹。
  2. Now you can login:现在您可以登录:

mysql -u root -p mysql -u 根 -p

  1. Show the users with:向用户展示:

SELECT user, host FROM mysql.user; SELECT 用户,主机 FROM mysql.user;

  1. Verify there is one 'root' with host 'localhost'.验证有一个“root”与主机“localhost”。
  2. Change the host:更换主机:

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

  1. Exit the mysql program and close the Command Prompt window.退出 mysql 程序并关闭命令提示符窗口。
  2. Type Ctrl-C in the other Command Prompt window to stop the server, then close the Command Prompt Window.在另一个命令提示符窗口中键入 Ctrl-C 以停止服务器,然后关闭命令提示符窗口。
  3. Start MySQL as you normally would and verify that you can login.像往常一样启动 MySQL 并验证您是否可以登录。

I came here looking for a solution using Local by flywheel for wordpress development to the same problem, BUT, in a linux machine.我来到这里寻找使用本地飞轮进行 wordpress 开发的解决方案,但在 linux 机器上遇到了同样的问题。

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只需在Local创建的文件树下的conf/mysql/my.cnf.hbs文件中注释skip_name_resolve

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.变量skip_name_resolve提供了更好的性能,因为服务器不会每次都尝试解析连接客户端的名称或在主机名缓存中查找它们(甚至解析/搜索localhost ),但手册指出 config 也限制了@本地主机连接。 The solution is to copy the @localhost users with @127.0.0.1, like this:解决方法是用@127.0.0.1 复制@localhost用户,像这样:

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.其中::1是用于 IPv6 寻址的本地主机 This way we keep the root and local accounts limited to the local server;通过这种方式,我们将 root 和本地帐户限制在本地服务器上; 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.禁用skip_name_resolve还需要服务器具有可访问且快速的 DNS 解析器,以最大限度地减少延迟。

I noted that I can connect with a local phpmyadmin even if the user has @localhost;我注意到即使用户有@localhost,我也可以连接到本地的phpmyadmin 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.这是因为phpmyadmin通过本地 unix 套接字连接,这是一种用于进程间通信的特殊类型的文件,不需要网络。

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

Looks that you need to modify your hosts file.看起来你需要修改你的主机文件。 C:\\Windows\\System32\\Drivers\\etc\\hosts 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 127.0.0.1 本地主机

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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