php - 使用更新的MySQL库修复PHP数据库连接失败
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 127.0.0.1
- Check that PHP is correctly pointing to the right socket
- Try swapping localhost and 127.0.0.1 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。