Home  >  Article  >  Backend Development  >  How to solve php incompatibility problem

How to solve php incompatibility problem

藏色散人
藏色散人Original
2021-02-07 09:29:032958browse

Solution to PHP incompatibility: 1. Change "my.cnf" to specify the character set; 2. Update the existing character set through "alter user 'root'@'%' identified with..." Account password; 3. Reinstall Mysql8.0.

How to solve php incompatibility problem

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer.

Summary of incompatibility issues between PHP and Mysql8

After installing Mysql8.0, we need to work together with our original PHP. However, it was originally able to work with Mysql5.1 The code that works well together suddenly reports an error, and it seems that some extra work needs to be done.

报错:PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers

According to online information, Mysql8.0 changed the default character set to utfmb4, so the communication with the client (not just PHP) cannot be recognized. We need to change my.cnf to specify the characters. set.

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
报错:PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]

According to online information, it is caused by the incompatibility of the encryption method for user identity authentication. The default method in mysql8.0 is caching_sha2_password, which causes compatibility issues with older versions. The encryption method of the old version is mysql_native_password.

Recommended: "PHP Video Tutorial"

We can specify the encryption method to set:

# 新建用户,使用旧版加密方式设置密码
CREATE USER username@localhost identified with mysql_native_password by 'password';
# 更新已存在的账号密码加密方式
alter user 'root'@'%' identified with mysql_native_password by 'password';

But a better way is to add a line of default configuration :

[mysqld]
default_authentication_plugin = mysql_native_password
报错:Access denied for user 'root'@'localhost' (using password: YES)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'oss'@'%';
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

When I added permissions to other users, I got an error saying no permissions. The reason was that I accidentally deleted the root user. Although there are many documents on the Internet to solve this problem, after I rebuilt Although the root user has Grant_priv: Y, it still cannot successfully assign permissions, which gives me a headache.

Solution: Reinstall, refer to the article to install Mysql8.0.

Summary

What are the new features of mysql8.0? I didn’t check the documentation in detail, but the compatibility gave me a hard time first, but fortunately it was solved. After these three questions, my PHP program ran successfully. Now I am going to upgrade PHP5.1 to PHP7.

The above is the detailed content of How to solve php incompatibility problem. 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