mysql_connect(): No such file or directory

mysql_connect(): No such file or directory

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

mysql_connect(): No such file or directory

You are encountering a classic symptom of environment misconfiguration, specifically regarding how the PHP mysql_* extension locates your MySQL client libraries. The error message Warning: mysql_connect(): No such file or directory is misleading; it does not mean your database connection string failed to reach the server. Instead, it indicates that the PHP interpreter itself cannot find the shared library required to execute the mysql_connect() function.

In your specific scenario involving RedHat 7 and MySQL 3.23.58, you have hit a significant architectural wall. MySQL 3.23 is an extremely old version (released in 1999) that predates the modern client-server architecture used by PHP's default extensions today. The mysql_* extension bundled with standard PHP distributions generally targets MySQL 4.0 or higher, and often requires specific legacy libraries like libmysqlclient.so that may not be installed or linked correctly on your current RedHat installation.

When you successfully connect from Wamp on Windows, the environment is pre-configured with the necessary DLLs (Dynamic Link Libraries) that match the PHP version there. On Linux, however, PHP must dynamically load external .so files at runtime. If the extension isn't loaded, or if the underlying library file path is incorrect, PHP throws this "No such file or directory" error before it even attempts to parse your $host, $user, and $password variables.

To resolve this without upgrading MySQL (which you cannot do due to dependency constraints), you must verify that the legacy MySQL client libraries are actually present on the RedHat 7 system. You can check for the existence of the required shared object file using the following command:

ls -l /usr/lib64/libmysqlclient.so*
# or potentially in /usr/lib32 if your PHP is a 32-bit build
ls -l /usr/lib/libmysqlclient.so*

If these files do not exist, your package manager (likely rpm or yum for RedHat) needs to install the specific development packages for MySQL. Since you cannot update libraries freely, you might need to locate the exact RPM file that matches your existing installation and use rpm -ivh --force to ensure all client headers are present.

Once the library files are located, you must ensure PHP is actually loading them. Check your active PHP configuration by running:

php -m | grep mysql

If this returns nothing, the extension isn't loaded. You may need to enable it in php.ini or add a line like extension=mysql.so (note that the filename might be libmysql.so on older systems) directly into your configuration file.

There is a critical trade-off here: even if you get the connection working, the PHP MySQL extension (mysql_connect) is deprecated as of PHP 5.5 and removed entirely in PHP 7.0+. Using it on a modern system is insecure because it does not support prepared statements, making your application highly vulnerable to SQL injection attacks. Since you are stuck with MySQL 3.23, the legacy extension is technically one of the few ways to talk to that specific version using standard PHP tools.

If you cannot get the legacy library working on RedHat 7, the only viable path forward to secure your codebase is to migrate away from mysql_connect(). The recommended approach for modern applications is to switch to PDO or MySQLi. However, you mentioned PDO is incompatible with 3.23. In such a constrained legacy environment, you might consider using a PHP wrapper that abstracts the connection or running a proxy script that handles the legacy connection logic on a separate machine with a newer PHP version, communicating via TCP/IP rather than local sockets. This isolates the deprecated code without forcing an upgrade of your core database server.

For more information on modernizing legacy PHP applications and handling database migrations, resources like https://laravelcompany.com discuss strategies for upgrading stack components safely.

Our network