Search code examples
mysqllocalhostcygwin

$ mysql -u root -p -h 127.0.0.1 Enter password: ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)


I am just a beginner to the programming world. I spent more than 14 hours making dozens of changes suggested in various answers on this site, but unsuccessful. Can some one help me?

I installed MySQL thru Cygwin.

I do not see my.cnf file, but do have 4 files, my-small.cnf to my-huge.cnf files, in C:\cygwin64\usr\share\mysql.

$ which mysql
/usr/bin/mysql.

And, have my-small.cnf, but no binding-localhost entry

[client]
 #password       = your_password
 host            = 127.0.0.1
 port            = 3306
 socket          = /var/run/mysql/mysql.sock

If I enter first line, it prompts for password, but, the prompt does not accept any password nor move. If I enter anything, it will display error message.

$ mysql -u root -p -h 127.0.0.1
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

OR, if I enter

$ mysql -u root -p -h localhost
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysql.sock' (2)

OR, for alias entry

$ mysql start
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

Solution

  • Please forgive me for using ELI5 Method for Explaining steps:

    It may be a good idea to UNINSTALL and RE-INSTALL:

    IF you have Completed the UN-INSTALLATION, then:

    Make sure that your Cygwin Shell is CLOSED

    Using Cygwin setup-x86_64 (OR, setup-x86.exe, as appropriate for your system) start installation

    Search in the top-left window and find:

    mysql
    
    mysqld
    

    Proceed to Install and ACCEPT its dependencies (RECOMMENDED)

    Once the installation is FINISHED

    START Cygwin Shell

    For Starting MySQL DATABASE setup:

    $ mysql_install_db
    

    IF Firewall alert: (Choose appropriate)

    For Running MySQL SERVER:

    $ mysqld_safe &
    

    IF Firewall alert: (Choose appropriate)

    For Starting MySQL Installation:

    $ mysql_secure_installation
    

    IF Firewall alert: (Choose appropriate)

    Answering Questions:

    root password: (Just enter, if you do not want)

    remove anonymous users: y

    disallow root login remotely: y (For the time being)

    remove test database and access to it: y

    reload privilege tables now: y

    Now Start MySQL SERVER:

    $ mysqld_safe
    

    Leave this window OPEN and you can MINIMIZE it if you want, and start another window using Alt+F2 OR using mouse by pointing to the top blue bar of the Cygwin Terminal (Window), then Right-click, and Click New

    For Starting MYSQL DATABASE, in NEW Window:

    yourPC@PCuser ~/usr/sbin

    (REPLACE yourPC & PCuser with the names you SEE on the Cygwin Terminal)

    $ mysql -u root -h localhost
    
    mysql> \h
    

    (You can read all the help)

    mysql> \q
    

    (For quitting mysql)

    For Shutting Down MySQL SERVER

    yourPC@PCuser ~/usr/sbin

    (REPLACE yourPC & PCuser with the NAMES you see on the Cygwin Terminal)

    $mysqladmin shutdown
    

    IF the above does NOT shutdown, then:

    $ mysqladmin -u root shutdown