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.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.
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
Open System Preference > MySQL > Initialize Database > Use Legacy Password Encription
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.
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.