php - 使用更新的MySQL库修复PHP数据库连接失败

原文 标签 php centos7 centos5 mysqlnd

Fixing a PHP database connection failure with updated MySQL library

I spent some hours trying to solve a migration from CentOS 5.5 to 7 in which everything worked except PHP-based sites connecting to the MySQL server for a Web site. Perl worked fine. CLI commands worked fine. I tried every solution listed on Stack Overflow and elsewhere:

  • Make sure /etc/hosts contains localhost as the first entry for
  • Check that PHP is correctly pointing to the right socket
  • Try swapping localhost and in the connection setup
  • Checked php.ini for any settings that differed between my functional CentOS 5.5 setup and the new stock CentOS 7 installation.

Annoyingly, I couldn't get PHP to dump errors, whether via Apache or elsewhere. It was all maddening.


After checking for the fifth time that I had the right drivers installed, I realized that there are two CentOS/yum packages: one is php-mysql; the other is php-mysqlnd, a native driver.

Uninstalling php-mysql, which is apparently outdated, but which is what I used in CentOS 5.5, and installed php-mysqlnd instantly fixed the problem.

I have been unable to find any other answers of this sort, so perhaps my situation is unique. But I wanted to document it in case someone else came across the same migration issue.


我花了几个小时来尝试解决从CentOS 5.5到7的迁移,其中除了基于PHP的站点连接到网站的MySQL服务器之外,其他一切都正常。 Perl工作正常。 CLI命令运行正常。我尝试了Stack Overflow和其他地方列出的所有解决方案:

确保/ etc / hosts包含localhost作为127.0.0.1的第一个条目
在php.ini中检查了我的功能性CentOS 5.5安装程序和新的库存CentOS 7安装之间是否有任何不同的设置。

在第五次检查我是否安装了正确的驱动程序后,我意识到有两个CentOS / yum软件包:一个是php-mysql;另一个是php-mysql。另一个是本地驱动程序php-mysqlnd。

卸载php-mysql显然已经过时了,但这是我在CentOS 5.5中使用的方法,并且安装了php-mysqlnd立即解决了该问题。


php - PHP代码不允许多个输入值通过我的表单发送

php - Laravel 5.1内部联接查询中的问题

php - 控制PHP ldap分页-结果数和页码

php - 带有PHPStorm 10的PHP7

php - 如何防止第二个正则表达式重新替换?

php - 如何在PHP的$ _SESSION中保存值并进行检索

php - 与特质的定义顺序和内容有关的“未找到特质错误”

php - 按费用和名称对数组进行排序

php - WAMP上的Mysqli,错误-连接尝试失败

php - laravel查询返回奇怪的顺序