Mysql

Mysql : Aborted connection …/… (讀取通訊包時出錯)

  • January 13, 2022

此錯誤資訊已在本論壇多次送出。

我嘗試了以下但沒有成功。

語境

這是一個 Symfony1/Doctrine1 網路應用程序。該錯誤出現在我的電腦和伺服器上(都在 Ubuntu 上)。在瀏覽器級別(Chrome)我有一個錯誤:

POST http://*****/administration_dev.php/utilisateur net::ERR_EMPTY_RESPONSE

在此處輸入圖像描述

這是我的電腦詳細資訊:

$ uname -a
Linux Bureau 4.4.0-31-generic #50-Ubuntu SMP Wed Jul 13 00:07:12 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS"
$ dpkg -l |grep php
ii  libapache2-mod-php                          1:7.0+35ubuntu6                                             all          server-side, HTML-embedded scripting language (Apache 2 module) (default)
ii  libapache2-mod-php7.0                       7.0.4-7ubuntu2.1                                            amd64        server-side, HTML-embedded scripting language (Apache 2 module)
ii  php                                         1:7.0+35ubuntu6                                             all          server-side, HTML-embedded scripting language (default)
.../...
$ dpkg -l |grep mysql-
ii  mysql-client-5.7                            5.7.13-0ubuntu0.16.04.2                                     amd64        MySQL database client binaries
ii  mysql-client-core-5.7                       5.7.13-0ubuntu0.16.04.2                                     amd64        MySQL database core client binaries
ii  mysql-common                                5.7.13-0ubuntu0.16.04.2                                     all          MySQL database common files, e.g. /etc/mysql/my.cnf
ii  mysql-server                                5.7.13-0ubuntu0.16.04.2                                     all          MySQL database server (metapackage depending on the latest version)
ii  mysql-server-5.7                            5.7.13-0ubuntu0.16.04.2                                     amd64        MySQL database server binaries and system database setup
ii  mysql-server-core-5.7                       5.7.13-0ubuntu0.16.04.2                                     amd64        MySQL database server binaries

當我在保存過程中嘗試創建新使用者時出現錯誤。

提議嘗試

#1 MySQL 讀取通信包時出錯

$ mysql -uroot -p -e "SET GLOBAL max_allowed_packet = 1024 * 1024 * 1024;"
Enter password: 
$ mysql -uroot -p -e "SHOW VARIABLES LIKE 'max_allowed_packet';"
Enter password: 
+--------------------+------------+
| Variable_name      | Value      |
+--------------------+------------+
| max_allowed_packet | 1073741824 |
+--------------------+------------+
$ tail -f -n0 /var/log/mysql/error.log
2016-07-24T19:41:32.736817Z 23 [Note] Aborted connection 23 to db: 'pfs2' user: 'pfs2' host: 'localhost' (Got an error reading communication packets)
2016-07-24T19:41:32.906433Z 24 [Note] Aborted connection 24 to db: 'pfs2' user: 'pfs2' host: 'localhost' (Got an error reading communication packets)
2016-07-24T19:41:33.056226Z 25 [Note] Aborted connection 25 to db: 'pfs2' user: 'pfs2' host: 'localhost' (Got an error reading communication packets)
2016-07-24T19:41:33.212496Z 26 [Note] Aborted connection 26 to db: 'pfs2' user: 'pfs2' host: 'localhost' (Got an error reading communication packets)
2016-07-24T19:41:33.363754Z 27 [Note] Aborted connection 27 to db: 'pfs2' user: 'pfs2' host: 'localhost' (Got an error reading communication packets)
2016-07-24T19:41:33.516194Z 28 [Note] Aborted connection 28 to db: 'pfs2' user: 'pfs2' host: 'localhost' (Got an error reading communication packets)
2016-07-24T19:41:33.668201Z 29 [Note] Aborted connection 29 to db: 'pfs2' user: 'pfs2' host: 'localhost' (Got an error reading communication packets)

#2 MySQL:讀取通信包時出錯

$ cat /etc/mysql/conf.d/david.cnf 
[mysqld]
sql-mode=NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_allowed_packet = 256M
innodb_log_buffer_size = 32M
innodb_log_file_size = 2047M
$ mysql -uroot -p -e "SET GLOBAL innodb_fast_shutdown = 0;"
$ sudo service mysql stop
$ sudo mv /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile0.bak
$ sudo mv /var/lib/mysql/ib_logfile1 /var/lib/mysql/ib_logfile1.bak
$ sudo service mysql start
$ tail -f -n0 /var/log/mysql/error.log
2016-07-24T19:56:02.342912Z 7 [Note] Aborted connection 7 to db: 'pfs2' user: 'pfs2' host: 'localhost' (Got an error reading communication packets)
2016-07-24T19:56:02.494024Z 8 [Note] Aborted connection 8 to db: 'pfs2' user: 'pfs2' host: 'localhost' (Got an error reading communication packets)
2016-07-24T19:56:02.642960Z 9 [Note] Aborted connection 9 to db: 'pfs2' user: 'pfs2' host: 'localhost' (Got an error reading communication packets)
2016-07-24T19:56:02.787908Z 10 [Note] Aborted connection 10 to db: 'pfs2' user: 'pfs2' host: 'localhost' (Got an error reading communication packets)
2016-07-24T19:56:02.933718Z 11 [Note] Aborted connection 11 to db: 'pfs2' user: 'pfs2' host: 'localhost' (Got an error reading communication packets)
2016-07-24T19:56:03.084066Z 12 [Note] Aborted connection 12 to db: 'pfs2' user: 'pfs2' host: 'localhost' (Got an error reading communication packets)
2016-07-24T19:56:03.235319Z 13 [Note] Aborted connection 13 to db: 'pfs2' user: 'pfs2' host: 'localhost' (Got an error reading communication packets)

我的想法和建議已經用完了,所以我在這裡尋求幫助。

感謝您的支持,如果您需要,我會為您提供更多資訊。

大衛。

解決方案在程式碼中。在關閉打開的 sql 事務之前,似乎沒有處理 PHP 異常並且應用程序崩潰。

mysql 錯誤消息的來源可能來自這種不舒服的狀態,我不能多說。

羅蘭多,謝謝你的時間。

您在一台伺服器上執行 MySQL 5.7 和 PHP。這表明您的伺服器並非專用於 MySQL。PHP 和 MySQL 顯然在爭奪 RAM。

我也沒有看到任何設置 InnoDB 緩衝池大小的嘗試。innodb_buffer_pool_size的預設值為128M (134217728)。

請記住一些關於max_allowed_pa​​cket的資訊。正如變數名所暗示的,它是 MySQL Packet 允許的最大大小。根據 MySQL 文件,MySQL 數據包開始時不是 1G。它的初始大小基於net_buffer_length的值。MySQL Packet 將根據需要動態擴展為max_allowed_pa​​cket

您嘗試調整 MySQL 數據包將因缺少 RAM 而無效。

建議 #1

  • 在可以是專用 Web 伺服器的另一台伺服器上安裝 PHP。
  • 增加 DB 伺服器上的 RAM 量

建議 #2

如果您買不起另一台伺服器,則只需增加 RAM 和緩衝池大小。

建議#3(可選)

由於您使用的是 MySQL 5.7,因此您可以動態擴展緩衝池。

執行以下操作將其設置為 2GB:

mysql> SET GLOBAL innodb_buffer_pool_size = 1024 * 1024 * 1024 * 2;

引用自:https://dba.stackexchange.com/questions/144773