Tag: 连接预览模式: 普通 | 列表
09-03
04

远程连接mysql超时的解决办法

远程连接mysql超时的解决办法PHP远程连接MYSQL速度慢,有时远程连接到MYSQL用时4-20秒不等,本地连接MYSQL正常,出现这种问题的主要原因是,默认安装的MYSQL开启了DNS的反向解析,在MY.INI(WINDOWS系统下)或MY.CNF(UNIX或LINUX系统下)文件的[mysqld]下加入skip-name-resolve这一选项就能禁用DNS解析,连接速度会快很多。不过,这样的话就不能在MySQL的授权表中使用主机名了而只能用ip格式。
附录:( How MySQL uses DNS )

引用内容 引用内容
When a new thread connects to mysqld, mysqld will spawn a new thread to handle the request. This thread will first check if the hostname is in the hostname cache. If not the thread will call gethostbyaddr_r() and gethostbyname_r() to resolve the hostname.

If the operating system doesn't support the above thread-safe calls, the thread will lock a mutex and call gethostbyaddr() and gethostbyname() instead. Note that in this case no other thread can resolve other hostnames that is not in the hostname cache until the first thread is ready.

You can disable DNS host lookup by starting mysqld with --skip-name-resolve. In this case you can however only use IP names in the MySQL privilege tables.

查看更多...

Tags: 超时 连接

分类:Database | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 799
     MySQL 的默认设置下,当一个连接的空闲时间超过8小时后,MySQL 就会断开该连接,而 c3p0 连接池则以为该被断开的连接依然有效。在这种情况下,如果客户端代码向 c3p0 连接池请求连接的话,连接池就会把已经失效的连接返回给客户端,客户端在使用该失效连接的时候即抛出异常。
  解决这个问题的办法有三种:
  1. 增加 MySQL 的 wait_timeout 属性的值。
  修改 /etc/mysql/my.cnf文件,在 [mysqld] 节中设置:
  # Set a connection to wait 8 hours in idle status.
  wait_timeout = 86400
  2. 减少连接池内连接的生存周期,使之小于上一项中所设置的 wait_timeout 的值。
  修改 c3p0 的配置文件,设置:
  # How long to keep unused connections around(in seconds)

查看更多...

Tags: 连接 闲置

分类:Database | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 725