[mysql] 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.

This question is related to mysql

The answer is


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


  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"


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.


  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


Go to >system preferences >mysql >initialize database

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

it should work now


Go to system preferences, then "MySQL"

Click on "Start MySQL Server"

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


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.


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


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.


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

It will work surely


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.


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