Mysql

為什麼我的 MySQL 伺服器突然無法啟動。ERROR 2002 (HY000): 無法通過套接字 ‘/var/run/mysqld/mysqld.sock’ 連接到本地 MySQL 伺服器 (2)

  • February 4, 2021

突然我的 MySQL 伺服器無法啟動。

在 cli 中執行mysql將返回

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

我正在執行一個可能會殺死數據庫和/或將其置於過度負載下的程序。相同的過程在實時數據庫上導致了 504 錯誤(據稱),當它似乎凍結時,我在本地主機上執行了相同的過程。最終腳本“完成”(過程實際上並不成功)。但是完成後,我的 MySQL 死了,我無法復活它。

我在 Windows 10 下的 Virtual Box 上執行 Vagrant。過去發生過這種情況,我不得不重建整個 localhost 環境。由於各種原因,這會導致足夠的停機時間,並且數據庫的失去是有問題的。我想知道為什麼會發生這種情況以及如何讓它再次工作。

只是為了明確 MySQL 伺服器沒有執行。沒有要殺死的程序。重新啟動我的機器然後設置本地主機環境並不能解決這個問題。我犯了同樣的錯誤。

我現在花了好幾個小時在網際網路上尋找解決方案,但沒有成功。查看了所有 MySQL 配置文件,它們看起來不錯。嘗試以各種方式重新啟動 MySQL 伺服器。殺死程序。創建了一個具有正確權限和大量其他建議解決方案的 mysqld 文件夾。我沒有重新安裝我的 mysql 伺服器,因為我不想失去數據庫。

$ systemctl status mysql.service

● mysql.service - MySQL Community Server
  Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
  Active: failed (Result: exit-code) since Wed 2021-02-03 12:58:32 UTC; 26min ago
 Process: 2752 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=1/FAILURE)
 Process: 2730 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)

Feb 03 12:58:32 homestead systemd[1]: mysql.service: Failed with result 'exit-code'.
Feb 03 12:58:32 homestead systemd[1]: Failed to start MySQL Community Server.
Feb 03 12:58:32 homestead systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Feb 03 12:58:32 homestead systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
Feb 03 12:58:32 homestead systemd[1]: Stopped MySQL Community Server.
Feb 03 12:58:32 homestead systemd[1]: mysql.service: Start request repeated too quickly.
Feb 03 12:58:32 homestead systemd[1]: mysql.service: Failed with result 'exit-code'.
Feb 03 12:58:32 homestead systemd[1]: Failed to start MySQL Community Server.

$ journalctl -xe

--
-- The start-up result is RESULT.
Feb 03 13:07:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:08:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:09:00 homestead systemd[1]: Starting Clean php session files...
-- Subject: Unit phpsessionclean.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit phpsessionclean.service has begun starting up.
Feb 03 13:09:01 homestead CRON[2980]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 03 13:09:01 homestead CRON[2981]: (root) CMD (  [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi)
Feb 03 13:09:01 homestead CRON[2980]: pam_unix(cron:session): session closed for user root
Feb 03 13:09:01 homestead systemd[1]: Started Clean php session files.
-- Subject: Unit phpsessionclean.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit phpsessionclean.service has finished starting up.
--
-- The start-up result is RESULT.
Feb 03 13:09:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:10:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:11:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:12:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:13:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:14:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:15:01 homestead CRON[3048]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 03 13:15:01 homestead CRON[3049]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 03 13:15:01 homestead CRON[3048]: pam_unix(cron:session): session closed for user root
Feb 03 13:15:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:16:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:17:01 homestead CRON[3053]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 03 13:17:01 homestead CRON[3054]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 03 13:17:01 homestead CRON[3053]: pam_unix(cron:session): session closed for user root
Feb 03 13:17:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:18:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:19:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:20:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:21:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:22:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:23:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:24:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events
Feb 03 13:25:01 homestead CRON[3067]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 03 13:25:01 homestead CRON[3068]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Feb 03 13:25:01 homestead CRON[3067]: pam_unix(cron:session): session closed for user root
Feb 03 13:25:07 homestead env[845]: [APIv1] KEEPALIVE /api/v1/events

var/logs/mysql/error.log

2021-02-04T04:50:22.916611Z 0 [Note] Binlog end
2021-02-04T04:50:22.916664Z 0 [Note] Shutting down plugin 'CSV'
2021-02-04T04:50:22.916939Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

2021-02-04T04:50:23.442484Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-02-04T04:50:23.443904Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.27-0ubuntu0.18.04.1) starting as process 2399 ...
2021-02-04T04:50:23.449165Z 0 [Note] InnoDB: PUNCH HOLE support available
2021-02-04T04:50:23.449188Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-02-04T04:50:23.449195Z 0 [Note] InnoDB: Uses event mutexes
2021-02-04T04:50:23.449201Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2021-02-04T04:50:23.449206Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-02-04T04:50:23.449214Z 0 [Note] InnoDB: Using Linux native AIO
2021-02-04T04:50:23.449505Z 0 [Note] InnoDB: Number of pools: 1
2021-02-04T04:50:23.449607Z 0 [Note] InnoDB: Using CPU crc32 instructions
2021-02-04T04:50:23.452188Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2021-02-04T04:50:23.464668Z 0 [Note] InnoDB: Completed initialization of buffer pool
2021-02-04T04:50:23.466372Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-02-04T04:50:23.477777Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2021-02-04T04:50:23.478809Z 0 [Note] InnoDB: Log scan progressed past the checkpoint lsn 101344176183
2021-02-04T04:50:23.478854Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 101344232648
2021-02-04T04:50:23.487359Z 0 [Note] InnoDB: Database was not shutdown normally!
2021-02-04T04:50:23.487371Z 0 [Note] InnoDB: Starting crash recovery.
2021-02-04T04:50:23.501921Z 0 [Note] InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percent: 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
2021-02-04T04:50:23.512026Z 0 [Note] InnoDB: Apply batch completed
2021-02-04T04:50:23.639660Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-02-04T04:50:23.639718Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-02-04T04:50:23.646302Z 0 [Warning] InnoDB: 1048576 bytes should have been written. Only 1032192 bytes written. Retrying for the remaining bytes.
2021-02-04T04:50:23.646330Z 0 [Warning] InnoDB: Retry attempts for writing partial data failed.
2021-02-04T04:50:23.646339Z 0 [ERROR] InnoDB: Write to file ./ibtmp1failed at offset 11534336, 1048576 bytes should have been written, only 1032192 were written. Operating system error number 28. Check that your OS and file system support files of this size. Check also that the disk is not full or a disk quota exceeded.
2021-02-04T04:50:23.646348Z 0 [ERROR] InnoDB: Error number 28 means 'No space left on device'
2021-02-04T04:50:23.646354Z 0 [Note] InnoDB: Some operating system error numbers are described at http://dev.mysql.com/doc/refman/5.7/en/operating-system-error-codes.html
2021-02-04T04:50:23.646360Z 0 [ERROR] InnoDB: Could not set the file size of './ibtmp1'. Probably out of disk space
2021-02-04T04:50:23.646366Z 0 [ERROR] InnoDB: Unable to create the shared innodb_temporary
2021-02-04T04:50:23.646371Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2021-02-04T04:50:24.149465Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2021-02-04T04:50:24.149490Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2021-02-04T04:50:24.149496Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2021-02-04T04:50:24.149502Z 0 [ERROR] Failed to initialize builtin plugins.
2021-02-04T04:50:24.149507Z 0 [ERROR] Aborting

有沒有人有任何想法?我真的被困住了。:(

這些是最重要的資訊:

2021-02-04T04:50:23.646339Z 0

$$ ERROR $$InnoDB:在偏移量 11534336 處寫入文件 ./ibtmp1 失敗,應該已寫入 1048576 字節,僅寫入了 1032192。作業系統錯誤號 28。檢查您的作業系統和文件系統是否支持此大小的文件。還要檢查磁碟是否未滿或超出磁碟配額。

2021-02-04T04:50:23.646348Z 0$$ ERROR $$InnoDB:錯誤號 28 表示“設備上沒有剩餘空間

我猜想包含您的數據目錄的磁碟已滿

引用自:https://serverfault.com/questions/1052255