Solution to the problem that php7 cannot connect to mysql8: 1. Check whether the mysql process is started; 2. Add port information; 3. Modify the client port to be consistent with the server.
The operating environment of this article: Windows 10 system, PHP7&&mysql8 version, Dell G3 computer.
How to solve the problem that php7 cannot connect to mysql8?
Mysql 8 php 7 connection failure solution
When connecting to mysql 8, it prompts that the connection cannot be authorized. The error is as follows:
Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in C:\DISK\apache\Apache24\htdocs\oop\data\ sql.php on line 35
Connect Error (Access denied for user 'root'@'localhost' (using password: YES))
#ERROR will also appear when logging in under the Cmd command 1045(28000) I searched the reason online and found that the login method in version 8 was changed to caching_sha2_password, so I modified the user login method settings in the database as follows:
1. Use the mysql tool window to log in
2. Enter Command:
use mysql select user,host,plugin from user; (查看用户验证方式) update user set plugin=‘mysql_native_password’ where User=‘root’; FLUSH PRIVILEGES;
When logging in to mysql using cmd,
error 2003 (HY000): Can not connect to MySQL server on 'localhost' (10061)
1. Check whether the mysql process is started. If it is not started, in the cmd window, net start mysql process name.
2. When mysql is started, add port information: mysql -u root -P port number -p
#error 2007 protocal appears when
Cmd logs in mismatch the server version =11 the client version = 10
Use the mysql community tool to recheck the configuration during the update and find that the server port modification still does not take effect. Looking at the configuration again, it turns out that it was modified to the client port. So modify the client port to be consistent with the server port. Then use cmd to log in.
Summary:
2. Carefully analyze the problem phenomenon and the relationship between the problems
Recommended study: "
The above is the detailed content of How to solve the problem that php7 cannot connect to mysql8. For more information, please follow other related articles on the PHP Chinese website!