Mysql – Failed to connect to MySQL at localhost

connectionlocalhostMySQL

I recently installed MySQL on my machine using MySQL installer. I am using it as part of an Apache Tomcat server I'm running on localhost.

I linked the database to Netbeans and everything was working fine. A couple of weeks ago I accidentally shut off my machine – the battery became disconnected – and when I turned it back on I could not connect to the database.

Whether I tried to connect via the command line, MySQL workbench or Netbeans I got an error telling me I could not connect to the database.

I've tried the following to fix the problem
-Reinstalled MySQL server, workbench, etc
-Reinstalled MySQL in different location
-Stopped MySQL via the services window and started it again
-Reconnected to Netbeans

Here's an example of the errors.

I get this when testing the connection while creating a new connection in Workbench:

enter image description here

After I make a connection (ignoring the fact the connection test fails) and trying to connect (still in Workbench)

enter image description here

Can someone please please help me? This is for my final year college project and I haven't been able to do anything for the past couple of weeks because of this. It's really annoying and I've tried everything I can think of.

Best Answer

Open up command prompt and type :

netstat -anto | findstr 3306

If you get output the mysql server is running , else the server is not running in this case check mysql service status in services.msc