How to solve the error of PHP connection to mysql8

PHP version is 5.6. An error is reported when connecting to mysql8.0, but it is normal to connect to other versions before mysql8

The reason may be that mysql8 uses different password authentication methods by default, and mysql8.0 uses caching by default_sha2_Password, but previous versions used mysql_native_password


Modify the/etc/my.cnf file

Find default authentication plugin = MySQL_native_Password line

Cancel the # number in front and restart mysql. MySQL will be used by default_native_Password, and then use the previous PHP script to test the connection to MySQL

As follows. The root user marked by the red arrow can connect normally


Similar Posts: