Mysql 错误:‘无法通过套接字‘/var/run/mysqld/mysqld.sock’(111) 连接到本地 MySQL 服务器’

Mysql 错误:‘无法通过套接字‘/var/run/mysqld/mysqld.sock’(111) 连接到本地 MySQL 服务器’

我的服务器存在空间问题,因此我添加了更多空间,但现在 MySQL 无法启动。

尝试启动 mysql:

root@vps:~# /etc/init.d/mysql start
[....] Starting mysql (via systemctl): mysql.service
Job for mysql.service failed. See 'systemctl status mysql.service' and 'journalctl -xn' for details.

使用以下方法检查错误systemctl 状态 mysql.service:

root@vps412690:~# systemctl status mysql.service
● mysql.service - LSB: Start and stop the mysql database server daemon
   Loaded: loaded (/etc/init.d/mysql)
   Active: failed (Result: exit-code) since Thu 2018-11-08 09:33:42 CET; 11s ago
  Process: 21650 ExecStart=/etc/init.d/mysql start (code=exited, status=1/FAILURE)
Nov 08 09:33:42 vps mysql[21650]: .Warning: World-writable config file '/etc/mysql/my.cnf' is ignored
Nov 08 09:33:42 vps /etc/init.d/mysql[22203]: 0 processes alive and '/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping' resulted in
Nov 08 09:33:42 vps /etc/init.d/mysql[22203]: [61B blob data]
Nov 08 09:33:42 vps /etc/init.d/mysql[22203]: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)'
Nov 08 09:33:42 vps /etc/init.d/mysql[22203]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
Nov 08 09:33:42 vps /etc/init.d/mysql[22203]:
Nov 08 09:33:42 vps mysql[21650]: failed!
Nov 08 09:33:42 vps systemd[1]: mysql.service: control process exited, code=exited status=1
Nov 08 09:33:42 vps systemd[1]: Failed to start LSB: Start and stop the mysql database server daemon.
Nov 08 09:33:42 vps systemd[1]: Unit mysql.service entered failed state.

如果我尝试 apt-get(也许我缺少一些文件或者其他什么),它不起作用:

Errors were encountered while processing:
 mysql-server-5.5
 mysql-server
 nginx-full
 nginx
E: Sub-process /usr/bin/dpkg returned an error code (1)

在我的 var/log/mysql/error.log 文件中发现有趣的日志:

181108 10:05:31 InnoDB: The InnoDB memory heap is disabled
181108 10:05:31 InnoDB: Mutexes and rw_locks use GCC atomic builtins
181108 10:05:31 InnoDB: Compressed tables use zlib 1.2.8
181108 10:05:31 InnoDB: Using Linux native AIO
181108 10:05:31 InnoDB: Initializing buffer pool, size = 128.0M
181108 10:05:31 InnoDB: Completed initialization of buffer pool
181108 10:05:31 InnoDB: highest supported file format is Barracuda.
InnoDB: 1 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 1 row operations to undo
InnoDB: Trx id counter is 5F884400
InnoDB: Cleaning up trx with id 5F87FA74
181108 10:05:31  InnoDB: Waiting for the background threads to start
181108 10:05:32 InnoDB: 5.5.62 started; log sequence number 3969391541705
181108 10:05:32 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
181108 10:05:32 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
181108 10:05:32 [Note] Server socket created on IP: '0.0.0.0'.
181108 10:05:32  InnoDB: Assertion failure in thread 140603552634624 in file trx0purge.c line 843
InnoDB: Failing assertion: purge_sys->purge_trx_no <= purge_sys->rseg->last_trx_no
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
09:05:32 UTC - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed, 
something is definitely wrong and this may fail.

key_buffer_size=16777216
read_buffer_size=131072
max_used_connections=0
max_threads=151
thread_count=0
connection_count=0
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 346701 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0 thread_stack 0x30000
/usr/sbin/mysqld(my_print_stacktrace+0x33)[0x55b6743790f3]
/usr/sbin/mysqld(handle_fatal_signal+0x3e4)[0x55b674264b14]
/lib/x86_64-linux-gnu/libpthread.so.0(+0xf890)[0x7fe0e913c890]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37)[0x7fe0e7b32067]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x148)[0x7fe0e7b33448]
/usr/sbin/mysqld(+0x5944d5)[0x55b6744244d5]
/usr/sbin/mysqld(+0x59501e)[0x55b67442501e]
/usr/sbin/mysqld(+0x662d92)[0x55b6744f2d92]
/usr/sbin/mysqld(+0x658fb8)[0x55b6744e8fb8]
/usr/sbin/mysqld(+0x596ec5)[0x55b674426ec5]
/usr/sbin/mysqld(+0x587f2c)[0x55b674417f2c]
/usr/sbin/mysqld(+0x58c723)[0x55b67441c723]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x8064)[0x7fe0e9135064]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7fe0e7be562d]
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.

df-h /var/lib/mysql

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        40G   19G   19G  51% /

不确定从哪里开始调试这个问题,有什么线索吗?

答案1

这个答案扩展了评论部分的讨论:

为了确保您的 InnoDB 文件是健康的,您确实需要重新创建它们 - 如果您现在不这样做,以后可能会给您带来麻烦。要这样做:

  • 进行完整的数据库级别备份(包括所有用户、存储过程......)
  • 由于您现在有足够的空间,请使用类似下面的方法tar -cjf /var/libbackup-mysql.tar.bz2 /var/lib/mysql创建文件级备份(以防万一......)
  • 停止数据库服务器
  • 从 /var/lib/mysql 中删除所有内容
  • 重新启动数据库服务器,这将需要一些时间并重新创建一个空的 InnoDB 结构
  • 重新导入数据库级别备份

如果这不能恢复您的所有数据,您可以使用文件级备份重新开始。

答案2

这可能有上百种解释,但 systemctl status 的第一行很可能是一个有用的提示:

Nov 08 09:33:42 vps mysql[21650]: .Warning: World-writable config file '/etc/mysql/my.cnf' is ignored

如果您的配置文件没有被读取,那么确实会出现奇怪的问题。

另外,您是否尝试过强制连接到似乎已绑定的 IP 地址而不是 unix 套接字上的 mysql?

您是否也阅读了有关恢复的建议:

InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.

相关内容