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.

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:
MySQL server is not running.
MySQL server is listening for requests from a different port.
MySQL server has refused the connection.
Here are some solutions you can try:
1. Check if MySQL is running
sudo service mysql status
2. Check which port MySQL is using
sudo lsof -i -P -n | grep mysqld
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
(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;
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use





