Question

[Solved] Failed to Connect to MySQL at localhost:3306 with user root

I use Mysql Workbench to connect my database,[Hostname Port and Username are as shown in figure ,and password is right[1]

Hostname Port and Username are as shown in figure ,and password is right.When I click Test Connection ,it show as above.But if i use 3307 in place of 3306 as port,it connect sucessfully. What matter lead that and how I fix it?

I use macbook pro and I don’t know check which my.cnf. I use sudo vim /usr/local/mysql/my.cnf in terminal .
And the my.cnf is as below:

[mysqld] 
 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES            

And I rewite it as below:

[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
socket=/tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M 
[mysqldump]
quick 

But it does not work.

Solution #1:

Steps:

1 – Right click on your task bar –>Start Task Manager

2 – Click on Services button (at bottom).

3 – Search for MYSQL57

4 – Right Click on MYSQL57 –> Start

Now again start your mysql-cmd-prompt or MYSQL WorkBench

Respondent: shengfu zou

Solution #2:

Open System Preference > MySQL > Initialize Database > Use Legacy Password Encription

Respondent: Abhishek Singh

Solution #3:

Try to execute below command in your terminal :

mysql -h localhost -P 3306 -u root -p

If you successfully connect to your database, then same thing has to happen with Mysql Workbench.

If you are unable to connect then I think 3306 port is acquired by another process.

Find which process running on 3306 port. If required, give admin privileges using sudo.

netstat -lnp | grep 3306

Kill/stop that process and restart your MySQL server. You are good to go.


Execute below command to find my.cnf file in macbook.

mysql --help | grep cnf

You can change MySQL port to any available port in your system. But after that, make sure you restart MySQL server.

Respondent: Hau Le

Solution #4:

It worked for me this way:

Step1: Open System Preference > MySQL > Initialize Database.

Step2: Put password you used while installing MySQL.

Step3: Start MySQL server.

Step4: Come back to MySQL Workbench and double connect/ create a new one.

Respondent: Darshan Patel

Solution #5:

MySQL default port is 3306 but it may be unavailable for some reasons, try to restart your machine. Also sesrch for your MySQL configuration file (should be called “my.cnf”) and check if the used port is 3306 or 3307, if is 3307 you can change it to 3306 and then reboot your MySQL server.

Respondent: Ishan Dixit

Solution #6:

Go to system preferences, then "MySQL"

Click on "Start MySQL Server"

Go to system preferences, then “MySQL”.
Click on “Start MySQL Server”.

Respondent: J0ker98

Solution #7:

Go to >system preferences >mysql >initialize database

-Change password
-Click use legacy password
-Click start sql server

it should work now

Respondent: almawhoob

Solution #8:

I had this exact problem after my last windows update and none of the above solutions worked. I know it’s an old question, but if anyone has this problem in the future:

I managed to solve it by going to windows control panel > administrative tools > Component Services and finding “MySQL57” in the Services(local) list (I assume your server might have a slightly different name).

There I went to properties by right clicking and changed the Startup Type to Automatic under the General tab. Then I went on the Log On tab and checked “Allow Service to interact with Desktop”.

If none of that works, you can try checking the “This account” box and filling both password fields with the root password you set up after installing the server (leave account blank).

I know it’s a lot to do and most of these steps must be innefective, but I did it all at once and frankly have no clue which one solved the problem. Good luck I hope it helps.

Respondent: Ronald Milligan

Solution #9:

At rigth side in Navigator -> Instance-> Click on Startup/Shutdown -> Click on Start Server

It will work surely

Respondent: DatarturoRV

Solution #10:

  1. go to apple icon on the top left corn and click “System Preference”

  2. find “Mysql” at the bottom and click it

  3. “start Mysql server”

Respondent: Tobia John

Solution #11:

It failed because there is no server install on your computer. You need to Download ‘MySQL Community Server 8.0.17’ & restart your server.

Respondent: Yan Xu

Solution #12:

  1. set root user to mysql_native_password

$ sudo mysql -u root -p # I had to use “sudo” since is new installation

mysql:~ USE mysql;
mysql:~ SELECT User, Host, plugin FROM mysql.user;
mysql:~ UPDATE user SET plugin='mysql_native_password' WHERE User="root";
mysql:~ FLUSH PRIVILEGES;
mysql:~ exit;

$ service mysql restart

Respondent: Jackie Santana

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy