【问题标题】:Too many times in my logs - PDOException: SQLSTATE[HY000] [2002] No such file or directory我的日志中有太多次 - PDOException: SQLSTATE[HY000] [2002] No such file or directory
【发布时间】:2016-11-15 20:25:18
【问题描述】:

在过去的几天里,我的日志文件记录了数百个这样的错误,网站运行良好,我无法复制这个问题。我相信当网站上有大量流量时会发生错误(实际上在我的访问日志中,爬虫扫描网站时导致的错误更多)。

我在通过 Sequel Pro 导出数据库(几百 MB)时看到了类似的错误,在某些情况下“mysql 服务器已消失”,但如果我等待几秒钟并尝试重新连接,则导出继续。

我想知道是否有任何修复或是否有任何日志我可以检查以了解有关此错误的更多信息,我知道增加服务器资源可能会使错误消失,但我想确保这是真实的原因。

是否有任何我应该查看的 mysql 配置可能导致(或减轻)该错误?

我还有一个问题,我正在使用localhost作为主机连接到mysql,如果我将它更改为127.0.0.1,我会得到什么好处吗?

PS:后台是一个Laravel php应用,首页注册的错误越多(那个页面只执行了一个查询,很简单select * from table,表有

在某些情况下,我得到的第一个错误是“连接被拒绝”,然后是“没有这样的文件或目录”

2016-11-15 09:01:07 PDOException: SQLSTATE[HY000] [2002] Connection refused
2016-11-15 09:01:07 PDOException: SQLSTATE[HY000] [2002] No such file or directory

当我收到提到的错误时,mysql error.log 看起来是这样的(在这两种情况下,当我第一次收到“连接被拒绝”和当我刚收到“没有这样的文件或目录”时:

2016-11-15T09:01:07.630308Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-11-15T09:01:07.630539Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2016-11-15T09:01:07.867266Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-11-15T09:01:07.872957Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.16-0ubuntu0.16.04.1) starting as process 5603 ...
2016-11-15T09:01:07.897867Z 0 [Note] InnoDB: PUNCH HOLE support available
2016-11-15T09:01:07.897929Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-11-15T09:01:07.897945Z 0 [Note] InnoDB: Uses event mutexes
2016-11-15T09:01:07.897955Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2016-11-15T09:01:07.897964Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
2016-11-15T09:01:07.897973Z 0 [Note] InnoDB: Using Linux native AIO
2016-11-15T09:01:07.899168Z 0 [Note] InnoDB: Number of pools: 1
2016-11-15T09:01:07.900244Z 0 [Note] InnoDB: Using CPU crc32 instructions
2016-11-15T09:01:07.902815Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2016-11-15T09:01:07.915239Z 0 [Note] InnoDB: Completed initialization of buffer pool
2016-11-15T09:01:07.917561Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2016-11-15T09:01:07.933388Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2016-11-15T09:01:07.938259Z 0 [Note] InnoDB: Log scan progressed past the checkpoint lsn 6776343956
2016-11-15T09:01:07.938307Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 6776343965
2016-11-15T09:01:07.938643Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 6776343965
2016-11-15T09:01:07.938665Z 0 [Note] InnoDB: Database was not shutdown normally!
2016-11-15T09:01:07.938678Z 0 [Note] InnoDB: Starting crash recovery.
2016-11-15T09:01:08.434497Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2016-11-15T09:01:08.434545Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2016-11-15T09:01:08.434598Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2016-11-15T09:01:08.464096Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2016-11-15T09:01:08.465115Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2016-11-15T09:01:08.465130Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2016-11-15T09:01:08.465391Z 0 [Note] InnoDB: Waiting for purge to start
2016-11-15T09:01:08.515613Z 0 [Note] InnoDB: 5.7.16 started; log sequence number 6776343965
2016-11-15T09:01:08.516097Z 0 [Note] Plugin 'FEDERATED' is disabled.
2016-11-15T09:01:08.516403Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2016-11-15T09:01:08.530024Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2016-11-15T09:01:08.530080Z 0 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
2016-11-15T09:01:08.530102Z 0 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
2016-11-15T09:01:08.530142Z 0 [Note] Server socket created on IP: '127.0.0.1'.
2016-11-15T09:01:08.539042Z 0 [Note] InnoDB: Buffer pool(s) load completed at 161115  9:01:08
2016-11-15T09:01:08.566608Z 0 [Note] Event Scheduler: Loaded 0 events
2016-11-15T09:01:08.566918Z 0 [Note] /usr/sbin/mysqld: ready for connections.

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    使用 '127.0.0.1' 和 'localhost' 的区别在于 mysql 会尝试使用标准网络机制或使用本地机器套接字进行连接(推荐使用这个,因为它更快)

    出现错误是因为 Doctrine 有某种“本地主机套接字检测器”,在某些情况下似乎会失败,如此处所述

    PDOException SQLSTATE[HY000] [2002] No such file or directory

    Troubleshooting "No such file or directory" when running `php app/console doctrine:schema:create`

    最好的解决方案(使用 127.0.0.1 它对我来说看起来不太好)是发现套接字位置

    mysql> show variables like 'socket';
    +---------------+-----------------------------+
    | Variable_name | Value                       |
    +---------------+-----------------------------+
    | socket        | /var/run/mysqld/mysqld.sock |
    +---------------+-----------------------------+
    

    并将该值传递给 php 上的 mysql 连接器(在 laravel 中,它似乎位于 database.php 中)

    【讨论】:

    • 感谢您的回答,实际上我已经在我的实时服务器上将它定义为空,我会在接下来的几个小时内看看它是如何进行的。你知道为什么这个错误只是偶尔发生吗?找不到插座的原因可能是什么?谢谢
    • 好的,大约 30 分钟后我再次遇到同样的错误(这次在大约 30 秒内记录了大约 130 次失败),我可能会再等几个小时,然后我会尝试使用 127.0.0.1看看是否有任何变化。这次我得到了一个不同的错误[ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12[ERROR] InnoDB: Cannot allocate memory for the buffer pool,我读到创建交换空间可以解决问题,另一方面here 他们建议不要这样做(我的服务器使用 SSD驱动器)
    猜你喜欢
    • 2023-04-01
    • 1970-01-01
    • 2019-07-24
    • 1970-01-01
    • 2021-07-05
    • 2015-04-04
    • 2013-10-08
    • 2015-04-22
    • 2023-04-01
    相关资源
    最近更新 更多