今天发现生产机上MYSQL有如下报错:[select count(*) from black where ver>'10120401']
<2002-Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'>[insert into data values( 21495, '2010-12-26 21:15:10', 004700, '260101114002', '\'bd\'bb\'d2\'d7\'c3\'f7\'cf\'b8', '\'c5\'fa\'d7\'bc', '15347581310200087823', '2010-12-26 15:04:10', 29.80, 139.10, '260101114', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )]
<2013-Lost connection to MySQL server during query>[select count(*) from black where ver>'10120401']
<1040-Too many connections>这台机器原来是正常工作将近4,5的 最近因为应用需求大约增加了1/4的客户端数量 然后就开始在应用日志中出现这些问题 
出现问题以后 有的时候服务器会自行恢复正常 但有的时候需要重启服务器才能解决请问各位大虾是为什么 该如何解决 谢谢 另外哪里可以看到mysql自己的数据库日志 
机器是linux平台的

解决方案 »

  1.   

    数据库日志在data目录下查看; 
    1040-Too many connections
    估计楼主的的connections 设置要加大一点;
      

  2.   

    <1040-Too many connections>太多并发连接了,调整一下你的MYSQL的max_connections 参数以允许更多连接。不过建议从根本上限制你的并发连接数。 
      

  3.   

    当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
    http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
    http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html8、如何给分和结贴?
    http://community.csdn.net/Help/HelpCenter.htm#结帖
      

  4.   

    已经有多少个连接了? 
    show status like 'Threads_connected';
      

  5.   

    经过调整max_connections <1040-Too many connections>这个错误已经不发生了 
    但是还是会有<2013-Lost connection to MySQL server during query>
    请各位大大 再帮忙看看 谢谢了
      

  6.   

    mysql的日志里看到101230 14:02:06  mysqld started
    101230 14:02:06  /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2)
    /usr/sbin/mysqld: ready for connections.
    Version: '4.0.20-log'  socket: '/var/lib/mysql/mysql.sock'  port: 3306
    101230 14:02:16  Aborted connection 2 to db: 'monitor' user: 'root' host: `localhost' (Got an error reading communication packets)
    101230 14:02:20  Aborted connection 3 to db: 'monitor' user: 'root' host: `localhost' (Got an error reading communication packets)
    101230 14:02:24  Aborted connection 5 to db: 'monitor' user: 'root' host: `localhost' (Got an error reading communication packets)
    101230 14:02:28  Aborted connection 6 to db: 'monitor' user: 'root' host: `localhost' (Got an error reading communication packets)
    101230 14:02:39  Aborted connection 7 to db: 'monitor' user: 'root' host: `localhost' (Got an error reading communication packets)
    101230 14:03:34  Aborted connection 8 to db: 'monitor' user: 'root' host: `localhost' (Got an error reading communication packets)
    101230 14:04:06  Aborted connection 9 to db: 'monitor' user: 'root' host: `localhost' (Got an error reading communication packets)
    101230 14:06:00  Aborted connection 10 to db: 'monitor' user: 'root' host: `localhost' (Got an error reading communication packets)中间都这个错误 所以省略 下面只贴最后一行101230 23:13:43  mysqld ended在应用程序日志看到的错误是
    20101230222540-ER: [select count(*) from black where ver>'10120401']:<2013-Lost connection to MySQL server during query>!
    20101230231352-ER: [select * from term where term_id='000001004852']<2002-Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)>!出现问题时 手工也无法登陆mysql 要重启服务器后 才能解决
      

  7.   

    网上一搜:
    经常会有使用mysql的朋友会发现error.log中有大量的
    [Warning] Aborted connection 。。(Got an error reading communication packets)
    对于这样的警告日志,大致从下面两个方面排查
    1网络问题,网络是否存在问题,花费了超过 connect_timeout 的时间去得到一个数据包
    2账号密码是否正确
    3客户端是否有权限连接该数据库
    4连接包是不是有带有正确的信息如果都不是上面的问题,可以尝试加大max_allowed_packet_size,或者使用php的短连接,不使用长连接,再或者每次查询完成后关闭连接,避免The client had been sleeping more than wait_timeout or interactive_timeout seconds without issuing any requests to the server.(客户端连接休眠时间超过wait_timeout,interactive)
    实在没招了,可以大概general query log,把所有查询的sql都列出来。
    还是解决不了,就是更底层的原因了,网络设备故障等等。详细见参考
    参考http://dev.mysql.com/doc/refman/5.1/en/communication-errors.html
      

  8.   


    我修改了max_allowed_packet 可是问题依旧
    另外服务器与mysql数据库是一台机器 应该不存在网络问题
      

  9.   

    查查你的sql,还有种原因可能就是你的sql语句效率低下引起的.
      

  10.   


    20101230222540-ER: [select count(*) from black where ver>'10120401']:<2013-Lost connection to MySQL server during query>!
    20101230231352-ER: [select * from term where term_id='000001004852']<2002-Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)>!这两张表里的数据 black 不超过200条记录 term 不超过4000条记录 其他表只有
    [insert into data values( 21495, '2010-12-26 21:15:10', 004700, '260101114002', '\'bd\'bb\'d2\'d7\'c3\'f7\'cf\'b8', '\'c5\'fa\'d7\'bc', '15347581310200087823', '2010-12-26 15:04:10', 29.80, 139.10, '260101114', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )]
    但是这个表的数据被另一个程序取走后 是会被删除的系统原先已经正常运行了5,6年了 就最近一个星期出现这样的问题(没有做过改动) 我感觉束手无策啊
      

  11.   

    会不会是表坏了? check table
    检查下所有表。
      

  12.   

    意外在监控信息上看到MYSQL 发生问题时 SWAP使用了94% 几乎用尽 不知道和MYSQL停止 有没有关系 于是昨天增加了一倍的SWAP 并且在程序前增加了并发数的控制 交易高峰的时候 终于没有再发生宕机的情况了 而且早上再看SWAP 只用了3% 
    感谢大家给予的帮助 O(∩_∩)O