Home  >  Article  >  Backend Development  >  How to solve the problem that php7 cannot connect to mysql8

How to solve the problem that php7 cannot connect to mysql8

藏色散人
藏色散人Original
2022-01-06 10:06:143117browse

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.

How to solve the problem that php7 cannot connect to mysql8

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;

Question 1:

When logging in to mysql using cmd,

error 2003 (HY000): Can not connect to MySQL server on 'localhost' (10061)

Steps:

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

Question 2:

#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.

How to solve the problem that php7 cannot connect to mysql8Summary:

1. Familiar with mysql configuration and principles

2. Carefully analyze the problem phenomenon and the relationship between the problems

Recommended study: "

PHP video tutorial

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!

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