You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装php5-mysqlnd后MySQL连接断开及连接数异常问题

Troubleshooting MySQL Connection Issues After Switching to php5-mysqlnd on Ubuntu 14.04

Hey there, let’s tackle this connection problem you’re seeing after switching from php5-mysql to php5-mysqlnd. That weird value 18446744073709551613 in phpinfo()? That’s actually the unsigned 64-bit integer representation of -1—a clear sign there’s an internal counting overflow or connection tracking bug with mysqlnd in your setup. Here’s what you can try to fix this:

Step 1: Tune MySQLnd Configuration in php.ini

First, let’s make sure your mysqlnd settings are configured correctly. Open your Apache PHP config file (usually at /etc/php5/apache2/php.ini) and verify these values:

  • Set mysqlnd.collect_statistics = On (this ensures connection stats are tracked properly; sometimes this gets disabled accidentally)
  • Adjust connection timeouts to prevent premature disconnections:
    mysqlnd.net_read_timeout = 60
    mysqlnd.net_write_timeout = 60
    

Save the file and restart Apache with sudo service apache2 restart.

Step 2: Confirm MySQLnd Module is Loaded

Sometimes the mysqlnd module doesn’t load correctly after installation. Run this command to check:

php -m | grep mysqlnd

If mysqlnd doesn’t show up in the output, enable it manually and restart Apache:

sudo php5enmod mysqlnd
sudo service apache2 restart

Step 3: Check MySQL Connection Limits

It’s possible your MySQL server is hitting its maximum connection limit, which can cause unstable connections and messed-up stats. Check your current max connections setting:

mysql -u root -p -e "SHOW VARIABLES LIKE 'max_connections';"

If the value is low (the default is often 151), increase it in your MySQL config (/etc/mysql/my.cnf):

max_connections = 200

Save the file and restart MySQL:

sudo service mysql restart

Step 4: Update PHP Packages (Critical for Ubuntu 14.04)

Ubuntu 14.04’s PHP 5.5 packages have known bugs with mysqlnd, especially around connection tracking. Make sure all your PHP packages are up to date:

sudo apt-get update && sudo apt-get upgrade php5-mysqlnd php5-cli php5-common

After updating, restart both Apache and MySQL to apply changes.

Step 5: Dig Into Error Logs for Clues

Don’t skip this! Error logs will give you specific details about why connections are dropping:

  • Apache error log: /var/log/apache2/error.log
  • MySQL error log: /var/log/mysql/error.log
    Look for entries like "Connection timed out", "Too many connections", or "Lost connection to MySQL server"—these will point you directly to the root cause.

If you’re using persistent connections (like mysql_pconnect or PDO’s PDO::ATTR_PERSISTENT), try disabling them temporarily. Older mysqlnd versions had bugs with persistent connection counting that caused this overflow issue.


内容的提问来源于stack exchange,提问作者koalacombatsystems

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:16:27