As you can read in my previous post related to MySQL 9 and authentication, the old mysql_native_password plugin has been removed.
In that post, I showed an example using PHP 7.2, the default version in OL8.
If you are using PHP and you want to use MySQL 9, you must be using a more recent version that fully supports the default authentication plugin caching_cha2_password.
Here is a summary table illustrating which PHP versions are compatible with MySQL 9:
This is the test using OL8 and PHP from the official repository and from Remi’s repo:
[root@mysql1 ~]# php test.php
PHP version: 7.2.24
PHP Warning: mysqli::__construct(): The server requested authentication method
unknown to the client [caching_sha2_password] in /root/test.php on line 9
PHP Warning: mysqli::__construct(): (HY000/2054): The server requested
authentication method unknown to the client in /root/test.php on line 9
Connection failed: The server requested authentication method unknown to the client
[root@mysql1 ~]# php test.php
PHP version: 7.2.34
PHP Warning: mysqli::__construct(): The server requested authentication method
unknown to the client [caching_sha2_password] in /root/test.php on line 9
PHP Warning: mysqli::__construct(): (HY000/2054): The server requested
authentication method unknown to the client in /root/test.php on line 9
Connection failed: The server requested authentication method unknown to the client
[root@mysql1 ~]# php test.php
PHP version: 7.3.33
PHP Warning: mysqli::__construct(): The server requested authentication method
unknown to the client [caching_sha2_password] in /root/test.php on line 9
PHP Warning: mysqli::__construct(): (HY000/2054): The server requested
authentication method unknown to the client in /root/test.php on line 9
Connection failed: The server requested authentication method unknown to the client
[root@mysql1 ~]# php test.php
PHP version: 7.4.33
Connected successfully
MySQL version: 9.0.0
[root@mysql1 ~]# php test.php
PHP version: 8.0.30
Connected successfully
MySQL version: 9.0.0
[root@mysql1 ~]# php test.php
PHP version: 8.1.29
Connected successfully
MySQL version: 9.0.0
[root@mysql1 ~]# php test.php
PHP version: 8.2.21
Connected successfully
MySQL version: 9.0.0
[root@mysql1 ~]# php test.php
PHP version: 8.3.9
Connected successfully
MySQL version: 9.0.0
Be ready to upgrade your legacy code to a newer version of PHP, it will be good for MySQL and PHP 😉
Enjoy coding in PHP and storing your data in MySQL!
lefred has been consulting OpenSource and MySQL for almost 20 years. After graduating in Management Information Technology, Frédéric started his career as a developer for an ERP under HPUX. He will then opt for a career in the world of open-source by joining one of the first Belgian start-up dedicated 100% to free projects around GNU/Linux. It is in 2011 that lefred joined Percona, one of the leading MySQL-based specialists. He decided to join the MySQL Community Team in 2016 as a MySQL Community Manager for EMEA & APAC. Frédéric is also a regular speaker of OpenSource Conferences. His blog mostly dedicated to MySQL is https://lefred.be Fred is also the devoted father of three adorable daughters: Wilhelmine, Héloïse & Barbara.
Previous Post