Check that mysql is running on server localhost

When you’re done installing a MySQL server application on Windows operating system, you can try to login to your MySQL server by using the mysql command from the Command Line.

But sometimes you may get the MySQL 2003 error saying it can’t connect to MySQL server as shown below:

mysql --user=[your username] --password=[your password]
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (10061)

The error above means that your request to connect to the MySQL server has been refused.

There are two things you need to check to fix this error:

  • Make sure that your MySQL service is actually running
  • Check that you are attempting to connect to the right port number

This tutorial will help you to do both, starting with checking MySQL service status.

Make sure that your MySQL service is actually running

To fix this error, you need to make sure that your MySQL server service is actually running in the Services panel.

First, open the Windows Start menu and search for the Services panel to see the result below:

Then, scroll through the services list until you reach the services that start with "M" to look for MySQL services.

Usually, you have the MySQL version number attached to the service name.

The MySQL version installed on my computer is MySQL 8.0.26 so I have MySQL80 service listed as shown below:

If you have MySQL version 7, then you may have MySQL70 listed on the Services panel.

As you can see from the picture above, the status of MySQL80 service is empty, meaning that it’s not currently running.

If you see the same status, you can run the service by clicking the Start the service link on the left pane.

Now you can try to connect again to your MySQL server from the Command Line.

MySQL service is missing from the Services panel

If you don’t find MySQL service from the Services panel, then you may not have installed MySQL as a Windows service.

It’s always recommended to install MySQL as a Windows service so that you can start and stop a running MySQL program easily.

To install the MySQL service, you can run the mysqld --install command from the command line as follows:

mysqld --install
Service successfully installed.

Please note that you need to have Administrator access to perform the installation above.

Alternatively, you can re-run the MySQL installer program and choose to reconfigure the installed MySQL server as shown below:

In the reconfigure wizard panel, click on Next until you get into the Windows Service section.

You should check the box that says Configure MySQL Server as a Windows Service as follows:

When you’re done, click on Next and then click on Execute to run the changes.

Now you should be able to find MySQL under the Services panel.

Check that you are attempting to connect to the right port number

When you run a MySQL service on your computer, the service will start MySQL server and allows you to connect to the server under a specific port number.

By default MySQL uses port 3306 but you can check the one you are currently using in your my.ini file.

The my.ini file is a MySQL configuration file used to properly configure the running MySQL services.

When you install MySQL using the official installer, then you should have a my.ini file located under your MySQL installation folder.

For example, mine was located under C:\ProgramData\MySQL\MySQL Server 8.0 folder as shown below:

Once you find the file, open it and find the [client] section.

You should find the port number assigned under the section as shown below:

[client]

# pipe=

# socket=MYSQL

port=3306

[mysql]
no-beep

Once you find the port number, and the number to the mysql command when you try to login as follows:

mysql --user=[your username] --password=[your password] --port=3306

Now you should be able to connect to your local MySQL server. Nice work! 👍

There are multiple ways to find the port which MySQL Server is listening. If you are already connected to MySQL server and you want to check the port, you can run the below query.

show variables where variable_name in ('hostname','port');

Another way to find out the port which MySQL Server is using on Windows is , Go to my.ini file that is MySQL configuration  file and you can check the port.

To find the my.ini file for MySQL Server, you can go to services and then go to properties.

my.ini file location for MySQL Server in Windows

Once you know the location of my.ini file, open the .ini file and look for port.

Check that mysql is running on server localhost

Check my.ini file for MySQL Port on which it is listening in Windows

Check out the video to see details how to find the port on which MySQL Servers are running

How do I find my localhost MySQL?

By default your MySQL host is localhost. You can find it in Hosting → Manage → MySQL databases section: If you are setting up a Remote MySQL connection, the host will be different and you will need to check it in the hPanel.

How do I know if MySQL is running on localhost Windows 10?

To check to see if MySQL is running, provided its installed as a service you can go to Start -> Control Panel -> Administrative Tools -> Services (i may be a bit off on those paths, I'm an OS X / Linux user), and look for MySQL on that list. See if it is started or stopped.

How do I run MySQL on localhost?

Testing your Local SQL Server Click on the “New Connection” icon and leave everything default, except the “Connection Name,” here enter localhost . Double click on the new connection and enter the password you created during installation. Voila! Let's run a command to make sure everything is working.

How do I know if MySQL is running on port 3306?

The correct way is using: sudo lsof -i :3306 .