Fix Missing MySQL Extension Error in WordPress
In this article
To fix the missing MySQL extension error in WordPress, you must ensure that the PHP MySQLi or PDO_MySQL extension is installed and enabled on your server. This is typically achieved by enabling the extension through your hosting control panel (like cPanel) or by installing the missing package via the command line on a VPS or dedicated server.
Understanding the Root Cause of the Error
WordPress is written in PHP and relies on a database—most commonly MySQL or MariaDB—to store all its content, including posts, pages, user data, and site settings. For PHP to communicate with the MySQL database, it requires a specific "bridge" or driver known as an extension. In the early days of WordPress, the original mysql extension was used, but this was deprecated in PHP 5.5.0 and completely removed in PHP 7.0.0.
Modern versions of WordPress use the mysqli (MySQL Improved) extension or PDO (PHP Data Objects). When you see a "missing MySQL extension" error, it means the PHP environment currently running on your server does not have the necessary driver loaded to talk to the database. This often happens after a PHP version upgrade, a server migration, or a fresh installation of a server stack (like LAMP or LEMP) where the default PHP installation is minimal and doesn't include database drivers.
Fixing the Error via cPanel and Shared Hosting
Most shared hosting environments provide a graphical user interface to manage PHP extensions. If you are using cPanel, you do not need to touch any code or command lines to resolve this issue. The process involves selecting the correct module for your active PHP version.
- Log in to your hosting account and access the cPanel dashboard.
- Search for the "Software" section and click on "Select PHP Version."
- You will see a list of available PHP extensions. Look for
mysqliandpdo_mysql. - Check the boxes next to these extensions to enable them.
- If you have recently changed your PHP version (e.g., from 7.4 to 8.2), you may need to re-enable these extensions for the new version, as settings do not always carry over automatically.
- Save the changes or wait for the system to apply them automatically, then refresh your WordPress site.
If you do not see a "Select PHP Version" option, look for "MultiPHP Manager." While this tool primarily manages the version, some hosts integrate the extension management within the specific version settings. If neither is available, the extension must be enabled by the host's system administrator.
Resolving the Issue on VPS or Dedicated Servers (Linux)
On a self-managed server, you have full control over the PHP configuration. The missing extension is usually a result of the package not being installed in the Linux repository. Depending on your operating system (Ubuntu, Debian, CentOS), the commands differ slightly.
For Ubuntu or Debian servers using Apache, you can install the extension using the apt package manager. First, identify your PHP version by running php -v. If you are using PHP 8.1, for example, you would run:
sudo apt updatesudo apt install php8.1-mysqlsudo systemctl restart apache2
If you are using Nginx, you must restart the PHP-FPM service instead of the web server to apply the changes:
sudo systemctl restart php8.1-fpm
For CentOS or RHEL systems using yum or dnf, the command would typically be sudo yum install php-mysqlnd. The mysqlnd (MySQL Native Driver) is the modern standard and is highly recommended over the older client libraries because it is written in C and integrated directly into the PHP source, offering better performance and memory management.
Verifying the PHP Configuration with phpinfo()
If you have attempted to enable the extension but the error persists, you need to verify what the server actually "sees." The most reliable way to do this is by creating a phpinfo file. This file outputs a comprehensive report of the current PHP configuration, including all loaded modules.
- Open a text editor and create a file named
info.php. - Inside the file, add the following code:
<?php phpinfo(); ?>. - Upload this file to the root directory of your WordPress installation (usually
public_html) using FTP or a File Manager. - Navigate to
yourdomain.com/info.phpin your web browser. - Use the browser's search function (Ctrl+F or Cmd+F) to search for "mysqli" or "pdo_mysql".
If the search returns no results, the extension is not loaded, regardless of what your control panel says. If it is listed, but you still see the error, the issue might be a mismatch between the PHP version used by the command line (CLI) and the PHP version used by the web server (Apache/Nginx). This is a common point of confusion for developers; fixing it in the CLI does not necessarily fix it for the website.
Common Misconceptions and Related Pitfalls
A frequent misconception is that the "missing MySQL extension" error means the MySQL database server itself is down. While a crashed database can cause connection errors, a "missing extension" error is specifically about the PHP software's ability to communicate, not the database's availability. If the database were down, you would more likely see "Error establishing a database connection."
Another common mistake is attempting to fix this by editing the wp-config.php file. While wp-config.php contains the database credentials (username, password, host), it cannot install or enable PHP extensions. Extensions are server-level configurations, not application-level settings. If you find tutorials suggesting you change the DB_HOST to fix a missing extension, be cautious; those are treating a different problem.
Furthermore, some users try to install outdated versions of PHP to "bring back" the old mysql extension. This is highly discouraged. Running an end-of-life PHP version exposes your site to severe security vulnerabilities and degrades performance. The correct path is always to ensure the modern mysqli or pdo_mysql extensions are active.
Safety and Maintenance Considerations
When modifying server configurations or installing packages, safety is paramount. Always perform a full backup of your website files and database before making changes to the server environment. While enabling a PHP extension is generally low-risk, restarting services like Apache or PHP-FPM can momentarily take your site offline.
To maintain a healthy environment and prevent this error from returning, consider the following practices:
- Standardize PHP Versions: Ensure that your CLI and Web Server are using the same PHP version to avoid discrepancies in extension availability.
- Use Managed Hosting: If you are not comfortable with the command line, managed WordPress hosting handles these extensions automatically during updates.
- Monitor PHP Updates: When you upgrade PHP via your host, always check the "Extensions" tab immediately to ensure
mysqliis checked. - Remove Debug Files: After using
phpinfo()to diagnose the issue, delete theinfo.phpfile immediately. Leaving it on your server is a security risk, as it reveals your server's internal paths, PHP version, and loaded modules to potential attackers.
Frequently Asked Questions
Will enabling the MySQLi extension slow down my site?
No, enabling the mysqli extension will not slow down your site. In fact, it is the required driver for WordPress to function. It is a lightweight module that allows PHP to send queries to the database efficiently. Without it, the site cannot load any content from the database.
Can I fix this by updating my WordPress plugins?
No, updating plugins or the WordPress core will not fix a missing MySQL extension. This error occurs at the server level (PHP), which is "below" the level of WordPress. Plugins rely on the extension being present; they cannot install the extension themselves because they do not have permission to modify server binaries.
What is the difference between mysqli and pdo_mysql?
mysqli is a driver specifically designed for MySQL databases and offers a wide range of features specific to MySQL. pdo_mysql is part of the PHP Data Objects (PDO) abstraction layer, which allows PHP to work with multiple different database types (like PostgreSQL or SQLite) using a consistent set of functions. WordPress primarily uses mysqli.
Why did this error suddenly appear after a PHP update?
When you upgrade to a new major version of PHP (e.g., 7.4 to 8.1), the server creates a new directory for that version's configuration. Often, the extensions enabled in the previous version are not automatically enabled in the new one. You must manually select the mysqli extension for the new version in your hosting panel.
Is the mysqlnd driver better than the standard mysql extension?
Yes, mysqlnd (MySQL Native Driver) is significantly better. It is designed specifically for PHP, providing better memory usage and allowing PHP to access more detailed information about the results returned by the database. Most modern Linux distributions use mysqlnd by default when you install the PHP MySQL package.