Home > Common Problem > How to solve the problem that mysql cannot connect to localhost

How to solve the problem that mysql cannot connect to localhost

尊渡假赌尊渡假赌尊渡假赌
Release: 2023-06-08 15:33:36
Original
7542 people have browsed it

The solution to the problem that mysql cannot connect to localhost is: 1. Check whether MySQL is running; 2. Confirm the port used by MySQL; 3. Check whether MySQL accepts connections from the local host; 4. Reinstall and configure MySQL.

How to solve the problem that mysql cannot connect to localhost

The operating system of this tutorial: Linux5.18.14 system, MySQL8. version, Dell G3 computer.

MySQL cannot connect to localhost (localhost), there may be several problems:

  1. MySQL server is not running.

  2. MySQL server is listening for requests from a different port.

  3. MySQL server has refused the connection.

Here are some solutions you can try:

1. Check if MySQL is running

sudo service mysql status
Copy after login

2. Check which port MySQL is using

sudo lsof -i -P -n | grep mysqld
Copy after login

3. Check whether MySQL accepts connections from local host

In mysql During startup, perform the following two steps.

(1) Enter mysql

mysql -u root -p
Copy after login

(2) Modify the binding IP to be empty, that is, any IP can access the mysql instance

use mysql;
update user set host='%' where user='root';
flush privileges;
Copy after login

4. If you still cannot connect , you may need to reinstall MySQL.

The above is the detailed content of How to solve the problem that mysql cannot connect to localhost. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template