Era Host hosting
EraHost – Free Domain, Cheap Hosting!
Client Area
Support 24/7
Menu

Updating MySQL Connector for PHP (MySQLi / PDO) to Fix Errors

3 min read
24.02.2026

Update MySQL Client Libraries

Sometimes, outdated MySQL client libraries cause authentication issues (e.g., mysql_native_password or caching_sha2_password). Update these libraries:

Update MySQL Connector PHP
PHP's MySQL driver = PHP version. Upgrade PHP to fix MySQL 8 issues.

For related MySQL connector topics, see MySql.Data 0x80004005, Update MySQL Connector (admin), native_password Access Denied, and MySQL Access Denied (admin).

1. Update the MySQL client:

  • Debian/Ubuntu:
    sudo apt update && sudo apt install libmysqlclient-dev
  • CentOS/RHEL:
    sudo yum update && sudo yum install mysql-community-libs

2. Restart the web server to apply the updated libraries:

sudo systemctl restart apache2

Linux VDS
High performance for your projects
  • Root access and flexible setup
  • Control panel
  • NVMe disks
  • DDR5
Linux VDS

Update the PHP MySQL Connector

If updating the system packages doesn't resolve the issue, explicitly update the PHP MySQL extension.

1. For PHP mysqli or PDO_MYSQL, reinstall the MySQL extension:

sudo apt install php-mysql

or for CentOS/RHEL:

sudo yum reinstall php-mysqlnd

2. Verify the version:

php -i | grep "mysqlnd"

It should show the latest mysqlnd version compatible with your PHP.

Check Database Connection Script

Ensure that your PHP code uses the correct credentials and connection settings. A modern MySQL server may require specific configurations.

Example: MySQLi

<?php
$host = "localhost";
$username = "myuser";
$password = "mypassword";
$database = "mydb";

$conn = new mysqli($host, $username, $password, $database);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully!";
?>

Example: PDO

<?php
$dsn = "mysql:host=localhost;dbname=mydb;charset=utf8mb4";
$username = "myuser";
$password = "mypassword";

try {
    $pdo = new PDO($dsn, $username, $password, [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    ]);
    echo "Connected successfully!";
} catch (PDOException $e) {
    die("Connection failed: " . $e->getMessage());
}
?>

Ensure Correct Authentication Plugin

Newer MySQL servers (8.0+) use caching_sha2_password by default, which older PHP connectors may not support. If this is the issue:

1. Check the authentication plugin for the MySQL user:

SELECT user, host, plugin FROM mysql.user WHERE user = 'myuser';

2. If the plugin is caching_sha2_password, switch to mysql_native_password:

ALTER USER 'myuser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypassword';
FLUSH PRIVILEGES;

Debugging Connection Issues

If the problem persists, enable error reporting in PHP to get more details about the issue:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>

Run your PHP script again and note the exact error message.

Final Test

Once everything is updated:

  1. Run the PHP script to test the connection.
  2. Ensure the application connects successfully to the MySQL database without any MySqlException.

By following these steps, a programmer can ensure the MySQL connector for PHP (MySQLi or PDO) is up-to-date, compatible with the server, and properly configured.

Frequently asked questions
Correct — PHP's MySQL support is via the bundled mysqlnd driver inside the mysqli or PDO_MySQL extension. Upgrading PHP version = upgrading mysqlnd. PHP 5.5 mysqlnd is ancient (no caching_sha2_password); PHP 7.4 mysqlnd handles it. So "update connector" = upgrade PHP.
No — caching_sha2_password support requires PHP 7.4+. For sites stuck on PHP 5.x: switch user back to mysql_native_password: `ALTER USER 'user'@'host' IDENTIFIED WITH mysql_native_password BY 'pw';`. Then PHP 5 can auth. Long-term, plan PHP upgrade.
Yes — PHP version change brings other API changes too (deprecations, removed functions). MySQL connectivity might work fine while application logic breaks elsewhere. Test app thoroughly post-upgrade; budget time for fixing PHP compat issues. Don't conflate "MySQL works" with "app works."
Modern PHP (7.4+) supports TLS 1.2 natively via mysqlnd. Older PHP may be limited to TLS 1.0/1.1. If MySQL server requires TLS 1.2 and PHP can't, connection fails. Upgrade PHP. Same applies for TLS 1.3 — only very recent PHP supports.
Related articles
Fixing MySqlConnector.MySqlException (0x80004005): Access Denied for User
Fixing MySqlException (0x80004005) by Updating MySQL Connector or Client
Using method 'mysql_native_password' failed with message: access denied for user