Home > Blockchain >  Nothing will connect to mysql on localhost
Nothing will connect to mysql on localhost

Time:11-20

I've tried just about everything I can find online. I'm going to try to make a complete list of all of the things that I have tried in no particular order (as it's been about two weeks of hunting for solutions). Where it all starts is my formerly functioning local dev setup was working fine aside from some SQL settings that were interfering with my already established codebase. I found resources online that detailed editing my.cnf file; which I did. From that point forward, nothing will connect to mysql.

1. Uninstall and remove mysql files via terminal

2. Reinstalled mysql and attempted to connect via terminal, didn't work
Running via terminal: mysql -u root
Resulting socket error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

3. Connected to services via DBngin
All services start up and seem to run fine; (Homebrew svcs: php, mysql, httpd). All show a green light and appear to be functioning.

4. Attempt to connect to mySQL via TablePlus
These settings worked before I messed with my.cnf file as described initially (no password):
Host: 127.0.0.1 Port: 3306 User: root

Resulting error: Can't connect to MySQL server on '127.0.0.1' (61)

5. Installed MySQL Workbench / Server, won't connect
Resulting error: SQLSTATE[HY000] [2002] Connection refused

6. Any attempt to load localhost:3306 in Chrome/Safari/Firefox all result in the following
SQLSTATE[HY000] [2002] Connection refused

7. See if mySQL is running

Run in terminal: ps aux |grep mysql

Results in: natashya 74640 0.0 0.0 34132100 908 s002 S 1:40pm 0:00.00 grep mysql

Try to kill via: kill 74640

Results in: kill: kill 74640 failed: no such process

Run: brew services restart mysql

Results in: ==> Successfully stopped `mysql` (label: homebrew.mxcl.mysql) ==> Successfully started `mysql` (label: homebrew.mxcl.mysql)

Contents of my.cnf

# Default Homebrew MySQL server config
# Only allow connections from localhost

[mysqld]

bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
port = 3306
mysqlx-port = 33060
socket = /var/lib/mysql/mysql.sock 
datadir = /usr/local/mysql
tmpdir = /tmp
mysqlx=OFF

[client]

port = 3306
socket = /var/lib/mysql/mysql.sock 

Thank you so much to Bill Karwin for help. I am however still unable to resolve the site I'm attempting to access (localhost:9000) and get this error: SQLSTATE[HY000] [2002] Connection refused

CodePudding user response:

Redux of the comment thread above:

  • Check the MySQL Server error log for clues.
  • The log indicated the directory for the socket files, /var/lib/mysql, did not exist.
  • Once the directory was created with the right permissions, the MySQL Server process created the socket file.

Also:

  • ps aux | grep mysql matches the process running grep mysql because the word 'mysql' appears in that command.
  • Related