无法连接:在“读取初始通信数据包”时丢失与 MySQL 服务器的连接,系统错误:0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/961928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:26:22  来源:igfitidea点击:

Could not connect: Lost connection to MySQL server at 'reading initial communication packet', system error: 0

mysqlrubydatabase-connection

提问by Steven

I am running a Rails app so now I am trying to remote connect to mysql and I am getting this error Could not connect: Lost connection to MySQL server at 'reading initial communication packet', system error: 0

我正在运行 Rails 应用程序,所以现在我正在尝试远程连接到 mysql,但出现此错误无法连接:在“读取初始通信数据包”时与 MySQL 服务器的连接丢失,系统错误:0

回答by Steven

You might want to check your /etc/hosts.denywhere:

你可能想检查你的/etc/hosts.deny在哪里:

ALL: ALL: DENY

or

或者

mysqld: ALL: DENY

is your enemy.

是你的敌人。

回答by Malcolm

Rebooting the server worked for me. No settings changes needed.

重新启动服务器对我有用。无需更改设置。

回答by noonex

check from that host

从该主机检查

shell> telnet IP 3306

If MySQL is up and reachable you'll see mysql version in telnet output. Otherwise check firewall, etc until telnet succeeds.

如果 MySQL 已启动且可访问,您将在 telnet 输出中看到 mysql 版本。否则检查防火墙等,直到 telnet 成功。

Then I advice you first connect with native mysql client to exclude Rails from problem aria.

然后我建议您首先连接本地 mysql 客户端以从问题 aria 中排除 Rails。

回答by Roch

You need to edit your mysql Configuration file, by default the bind-adressis set to 127.0.0.1.

您需要编辑您的 mysql 配置文件,默认情况下bind-adress设置为127.0.0.1.

Open: /etc/mysql/my.cnf

打开: /etc/mysql/my.cnf

Change the bind-adressto the ip you are going to use to connect yoursef to the database server.

将 更改为bind-adress您将用于将 yoursef 连接到数据库服务器的 ip。

回答by Federico Jaramillo

Enable remote access

启用远程访问

The MySQL server does not listen on the TCP port 3306 by default. To allow (remote) TCP connections, comment the following line in /etc/mysql/my.cnf:

MySQL 服务器默认不监听 TCP 端口 3306。要允许(远程)TCP 连接,请在 /etc/mysql/my.cnf 中注释以下行:

skip-networking

跳过网络

Remember to edit /etc/hosts.allow by adding the following lines:

请记住通过添加以下行来编辑 /etc/hosts.allow :

mysqld: ALL : ALLOW

mysqld:全部:允许

mysqld-max: ALL : ALLOW

mysqld-max: 全部 : 允许

回答by Wojtek Kruszewski

Using OS X? Does this issue go away for a while after mysqld restart and then re-appear? Check mysql server logs when getting these errors. I'm seeing a bunch of entries like below:

使用 OS X?mysqld 重启后这个问题会消失一段时间然后重新出现吗?收到这些错误时检查 mysql 服务器日志。我看到一堆如下的条目:

2019-01-30T17:34:04.009979Z 0 [Warning] File Descriptor 1564 exceeded FD_SETSIZE=1024

This error points to potential solutions: https://expressionengine.com/blog/mysql-5.7-server-os-x-has-gone-awayhttps://wilsonmar.github.io/maximum-limits/

此错误指向潜在的解决方案:https: //expressionengine.com/blog/mysql-5.7-server-os-x-has-gone-away https://wilsonmar.github.io/maximum-limits/

One of them is adding following setting to my.cnf

其中之一是将以下设置添加到 my.cnf

[mysqld]
table_open_cache=250

回答by Ben

mysqld-max: ALL : ALLOW solved the problem for me

mysqld-max: ALL : ALLOW 为我解决了这个问题

回答by Steven

Thank you guys for your effort, I have found the solution, I was suppose to set Remote Connection to MySQLhere is the link for someone who got the same error http://benrobb.com/2007/01/15/howto-remote-root-access-to-mysql/

谢谢你们的努力,我找到了解决方案,我想将远程连接设置为 MySQL 这里是遇到相同错误的人的链接 http://benrobb.com/2007/01/15/howto-remote- root-access-to-mysql/

回答by d1jhoni1b

As we all know there are many different ways to install and configure mySQL dbms (database managment system) on our machines besides the fact we all run different OS (linux, osx, win$hit, etc)

众所周知,除了我们都运行不同的操作系统(linux、osx、win$hit 等)之外,还有许多不同的方法可以在我们的机器上安装和配置 mySQL dbms(数据库管理系统)

In my case in particular i was getting

特别是在我的情况下,我得到了

connect': Lost connection to MySQL server at 'reading initial communication packet', system error: 102 (Mysql2::Error)

connect': Lost connection to MySQL server at 'reading initial communication packet', system error: 102 (Mysql2::Error)

BUTi did not even had /etc/hosts.denyi only had /etc/hostsbecause i installed mySQL on my OSX machine using simple GUI OSX app

但是我什至没有/etc/hosts.deny我只是/etc/hosts因为我使用简单的 GUI OSX 应用程序在我的 OSX 机器上安装了 mySQL

enter image description hereMySQL instance status was NOT OKabove's image is just a reference for MySQL OSX APP.

在此处输入图片说明MySQL 实例状态不正常上图仅供 MySQL OSX APP 参考。

Simple server re-start solved the issue.(in my case had to reboot my machine but that involves rebooting the MySQL server)

简单的服务器重新启动解决了这个问题。(在我的情况下必须重新启动我的机器,但这涉及重新启动 MySQL 服务器)

I was finally able to reach my localhost instance just fine again, did not had to change, create single file.

我终于能够再次访问我的本地主机实例,不必更改,创建单个文件。

Hope this helps, i see Malcolm's answer and comments and made me think it was good to post this.

希望这会有所帮助,我看到了Malcolm的回答和评论,并让我认为发布此内容很好。

回答by Jason FB

Nobody has seemed to answer this, and it appears to have re-emerged as an issue nearly 7 years after originally being filed. I saw this on Rails app running Capybara (using phantomjs), my integration specs (only) would intermittently fail with this.

似乎没有人回答这个问题,而且它似乎在最初提交近 7 年后重新成为一个问题。我在运行 Capybara(使用 phantomjs)的 Rails 应用程序上看到了这个,我的集成规范(仅)会间歇性地失败。

Restarting the machine temporarily fixed the problem.

重新启动机器暂时解决了问题。

I then imploded my MySQL installation completely (see https://community.jaspersoft.com/wiki/uninstall-mysql-mac-os-x) and re-installed it using homebrew. The problem appears to have gone away but I will update this answer if it comes back.

然后我完全内爆了我的 MySQL 安装(请参阅https://community.jaspersoft.com/wiki/uninstall-mysql-mac-os-x)并使用自制软件重新安装它。问题似乎已经消失,但如果它再次出现,我会更新此答案。

to implode your MySQL install completely (from https://community.jaspersoft.com/wiki/uninstall-mysql-mac-os-x):

完全内爆您的 MySQL 安装(来自https://community.jaspersoft.com/wiki/uninstall-mysql-mac-os-x):

Open a terminal window Use mysqldump to backup your databases to text files! Stop the database server

打开终端窗口 使用 mysqldump 将数据库备份到文本文件!停止数据库服务器

sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*

edit /etc/hostconfig and remove the line MYSQLCOM=-YES-

编辑 /etc/hostconfig 并删除行 MYSQLCOM=-YES-

rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*