MySQL错误 – 无法通过套接字连接到本地MySQL服务器

有时在我的VPS我得到的错误

Warning: mysql_pconnect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) in /var/www/mysql.php on line 8 

可以通过重新启动MySQL几次,重新启动服务器或者使用mysqld命令来解决。

使用mysqld命令我得到以下内容:

 root@web:~# mysqld 130109 10:47:23 [Note] Plugin 'FEDERATED' is disabled. 130109 10:47:23 InnoDB: The InnoDB memory heap is disabled 130109 10:47:23 InnoDB: Mutexes and rw_locks use GCC atomic builtins 130109 10:47:23 InnoDB: Compressed tables use zlib 1.2.3.4 130109 10:47:23 InnoDB: Initializing buffer pool, size = 128.0M 130109 10:47:23 InnoDB: Completed initialization of buffer pool 130109 10:47:23 InnoDB: highest supported file format is Barracuda. InnoDB: The log sequence number in ibdata files does not match InnoDB: the log sequence number in the ib_logfiles! 130109 10:47:23 InnoDB: Database was not shut down normally! InnoDB: Starting crash recovery. InnoDB: Reading tablespace information from the .ibd files... InnoDB: Restoring possible half-written data pages from the doublewrite InnoDB: buffer... 130109 10:47:24 InnoDB: Waiting for the background threads to start 130109 10:47:25 InnoDB: 1.1.8 started; log sequence number 43428438 130109 10:47:25 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306 130109 10:47:25 [Note] - '0.0.0.0' resolves to '0.0.0.0'; 130109 10:47:25 [Note] Server socket created on IP: '0.0.0.0'. 130109 10:47:25 [Note] Event Scheduler: Loaded 0 events 130109 10:47:25 [Note] mysqld: ready for connections. Version: '5.5.28-0ubuntu0.12.04.3' socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Ubuntu) 130109 10:47:25 [ERROR] mysqld: Table './sever/table' is marked as crashed and should be repaired 130109 10:47:25 [ERROR] mysqld: Table './sever/table' is marked as crashed and should be repaired 130109 10:47:25 [ERROR] mysqld: Table './sever/table' is marked as crashed and should be repaired 130109 10:47:25 [Warning] Checking table: './sever/table' 

我每天只有50个访问者,每小时使用超过3000个查询。 我的VPS只有一个内核256MB内存,运行在Ubuntu 64bit上。

MySQL的停机时间直接影响到我的网站,我无法在任何地方find答案。

提前致谢 :)

检查你的日志,你的表正在崩溃..

在继续之前,你应该修理它。 看到这个链接如何做到这一点

另外检查[hostname] .err MySQL错误日志文件。 它可以在/ var / lib / mysql或者/ var / log / syslog中

你应该看看日志(mysql错误日志,mysql查询日志,系统日志)条目, 当系统行为exception时,不是在你重新启动它之后。

这很可能是您达到了最大连接限制。

每天只有50个访问者,每小时使用超过3000个查询

erk,即使你使用的是Hibernate(但是你没有提到webserver和MySQL之间的内容),这是非常高的。

在这个时候,我会看看networkingstream量发生了什么 – 是否放缓 – 你是否交换了太多的东西 – 有多less用户连接。 还要检查mysqld进程发生了什么,然后再尝试重新启动 – 进程是否仍然存在?

我刚刚升级到512MB的Ram,它停了下来。 我认为这是Ladadadada提到的OOM杀手。 你可以在这里看到一个OOM杀手的Anseer 。