Home >Backend Development >PHP Problem >php connects to mysql and reports error 2054

php connects to mysql and reports error 2054

藏色散人
藏色散人Original
2019-10-23 09:10:114951browse

php connects to mysql and reports error 2054

php error 2054 when connecting to mysql?

The reason why this happens is mainly because of mysql8.0 version. The default encoding of version 8.0 is utf8mb4

Solution:

Add these two lines under [mysqld] in the MySQL configuration file my.ini

character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci

Then another problem appeared:

The server requested authentication method unknown to the client

It is also due to the mysql version, the 8.0 version mysql account The password unlocking mechanism is inconsistent

Enter the command in the database operation interface

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'account password';That's it

Or add

default_authentication_plugin=mysql_native_password

under [mysqld] in the MYSQL configuration file my.iniz. For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of php connects to mysql and reports error 2054. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn