71

I recently installed MySQL 5 on Windows 2003 and tried configuring an instance. Everything worked fine until I got to "Applying Security settings", at which point it gave me the above error (Can't connect to MySQL server on 'localhost' (10061)).

I do have a port 3306 exception in my firewall for 'MySQL Server'.

Ian Gregory
  • 5,770
  • 1
  • 29
  • 42
Cameron A. Ellis
  • 3,833
  • 8
  • 38
  • 46

19 Answers19

62

Got this error on Windows because my mysqld.exe wasn't running.

Ran "C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld" --install from the command line to add it to my services, ran services.msc (start -> run), found the MySQL service and started it.

Didn't have to worry about it from there on out.

ryanjones
  • 5,383
  • 4
  • 28
  • 24
49

To resolve this problem:

  1. go to the task manager
  2. select Services tab
  3. find MySql service
  4. Running

That's all.

TLama
  • 75,147
  • 17
  • 214
  • 392
JapoDeveloper
  • 615
  • 5
  • 4
32

You'll probably have to grant 'localhost' privileges to on the table to the user. See the 'GRANT' syntax documentation. Here's an example (from some C source).

"GRANT ALL PRIVILEGES ON %s.* TO '%s'@'localhost' IDENTIFIED BY '%s'";

That's the most common access problem with MySQL.

Other than that, you might check that the user you have defined to create your instance has full privileges, else the user cannot grant privileges.

Also, make sure the mysql service is started.

Make sure you don't have a third party firewall or Internet security service turned on.

Beyond that, there's several pages of the MySQL forum devoted to this: http://forums.mysql.com/read.php?11,9293,9609#msg-9609

Try reading that.

Sathish D
  • 4,854
  • 31
  • 44
Chris
  • 4,852
  • 1
  • 22
  • 17
7

English:

  • press Windows + R
  • write "services.msc". Then press Enter
  • search for MySQL57 and right click
  • click on start the service

Français :

  • Appuyez sur la touche Windows + R
  • Écrire "services.msc" Puis appuyez sur Entrée
  • Recherchez MySQL57 et clic droit
  • Cliquez sur rédémarrer
jpaugh
  • 6,634
  • 4
  • 38
  • 90
Sofia
  • 159
  • 2
  • 9
6

I had difficulty accessing MySQL while connecting via a localhost connection on the standard port 3306, which worked fine when I installed and configured it for prior classes I had taken in MySQL and Java. I was getting errors like "error 2003" and "Cannot connect to MySql server on localhost (10061)". I tried connecting from both MySQL Workbench (5.2.35 CE) and Netbeans (7.2). I am using Windows 7 64 bit professional.

I tried typing in services.msc in the start menu search box, which opened the services dialog box to show all the services installed in windows. I scrolled down to MySQL and started this service. Subsequent attempts to connect to MySQL from MySQL WorkBench and from the command prompt succeeded.

Colin
  • 719
  • 6
  • 3
  • 2
    The first paragraph of this answer is not relevant. Starting the service was already suggested by @RyanonRails – madth3 Nov 01 '12 at 01:36
5
  1. Make sure that your windows host file (located at c://windows/system32/drivers/etc.host) has following line. If not, add it at the end

    127.0.0.1 localhost
    ::1 localhost
    
  2. Sometimes mysql can not trigger Windows to force start host services if firewall blocks it, so start it manually

win+run>>services.msc, select the "MySQL_xx" where "xx" is the name you have assigned to MySQL host services during setup. Click on 'start' to start from hyperlink appeared on left side.

piet.t
  • 11,718
  • 21
  • 43
  • 52
Uday Hiwarale
  • 4,028
  • 6
  • 45
  • 48
  • win >> services.msc do the trick. But MySQL Workbench cannot restart the server. – IgniteCoders Nov 17 '17 at 05:11
  • The file is called hosts, not host. The path is `c:/windows/system32/drivers/etc/hosts` and I could only change it in admin mode (or you copy it somewhere, edit it there, and paste and overwrite confirming you are an admin) – questionto42 May 22 '20 at 17:52
  • and this has not solved the issue, I still cannot get access to my localhost. I am also confused why the hosts file did not have any entries before I changed it, there were only the comments that helped you what to insert. After your recommended change, I still cannot connect to 127.0.0.1, using the TCP/IP connection and the 3306 port in HeidiSQL. The error stays the same. – questionto42 May 22 '20 at 18:01
5

press Windows key + R write "services.msc" enter search for "MYSQL56" write click on it and start the service

Chetan Bhagat
  • 610
  • 6
  • 21
Mujtaba Zaidi
  • 629
  • 1
  • 6
  • 14
4

I tried Kuzhichamadam Inn's solution and found that a slight change needed to be made.

MYSQL57 was a network service. I had tried this repeatedly with no success. When I opened services.msc I found another service for localhost: MySQL. I started that one using the process below and it worked.

run > services.msc > rightclick MySQL > properties >start

Ted WIlcox
  • 41
  • 1
2

I got this error when I ran out of space on my drive.

MDave
  • 1,245
  • 13
  • 29
2

Go to Run type services.msc. Check whether or not MySQL services are running. If not, start it manually. Once it is started, type MySQL Show to test the service.

1

To connect locally to MySql, you do not have to setup a firewall with inbound rules. But, even if you already setup iptables to allow the TCP inbound port 3306 and grant the privilege to the user to access the db locally, you may have to setup the bind address in your my.cnf file, edit the default address there and put the server IP address that is running the MySql service.

Brian
  • 5,069
  • 7
  • 37
  • 47
1

Since I have struggled and found a slightly different answer here it is:

I recently switched the local (intranet) server at my new workplace. Installed a LAMP; Debian, Apache, MySql, PHP. The users at work connect the server by using the hostname, lets call it "intaserv". I set up everything, got it working but could not connect my MySql remotely whatever I did.

I found my answer after endless tries though. You can only have one bind-address and it cannot be hostname, in my case "intranet".

It has to be an IP-address in eg. "bind-address=192.168.0.50".

iknownothing
  • 354
  • 3
  • 9
1
run > services.msc > rightclick MySQL57 > properties >set start type option to automatic

after restarting computer

At cmd

cd: C:\

C :\> cd "C:\Program Files\MySQL\MySQL Server 5.7\bin"

it will become

C:\Program Files\MySQL\MySQL Server 5.7\bin>

type mysql -u root -p

ie C:\Program Files\MySQL\MySQL Server 5.7\bin> mysql -u root -p

Enter password: ****

That's all

It will result in

mysql>
Phiter
  • 14,570
  • 14
  • 50
  • 84
0

Another possibility:

There are two ways the MySQL client can connect to the server: over TCP/IP, or using sockets. It's possible you have your MySQL server configured to support socket connections, but not network connections.

dj_segfault
  • 11,957
  • 4
  • 29
  • 37
0

Nothing to do just "Reset to Default" your firewall setting it will start working.

I read many solutions but nothing worked properly, so at last I reset firewall settings which worked.

Tarun
  • 1
  • Shouldn't have to resort to this. I would check and make sure that both inbound and outbound firewall rules have been added. – Ren Apr 17 '13 at 08:37
0

finally solved this.. try running mysql in xammp. The check box of mysql in xammp should be unclicked. then start it. after that you can open now mysql and it will now connect to the localhost

  • 1
    This is from 5 years ago. Might want to delete this and post it as a comment since so much has changed, and it seems to be incomplete/irrelevant. – digitalextremist Dec 15 '13 at 04:06
0

Edit your 'my-default.ini' file (by default it comes with commented properties)as below ie.

basedir=D:/D_Drive/mysql-5.6.20-win32
datadir=D:/D_Drive/mysql-5.6.20-win32/data
port=8888

There is very good article present that dictates commands to create user, browse tables etc ie.

http://www.ntu.edu.sg/home/ehchua/programming/sql/MySQL_HowTo.html#zz-3.1

Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70
hmehandi
  • 356
  • 4
  • 11
0

I did not have Mysql server installed, that package was missing and I got it from this link https://dev.mysql.com/downloads/installer/

-3
  1. Right click on My Computer
  2. Click on Manage
  3. Go to Services and Application
  4. Select Services and find MySQL service
  5. Right click on MySQL and select Start