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
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
Since I've updated my Mac to the lastest OS version (Ventura 13.2) and I'he made some cleanup (hopefully I didn't remove any important file). I can't connect to mySql
I've insatlled mysql with brew (long before this update) and it always has worked fine.
When I run brew services start mysql in my terminal it looks to work (Successfully started mysql (label: homebrew.mxcl.mysql))
But, as soon as I run mysql -u root -p and I enter my password I have the following error message ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
When I explore /tmp directory I see that /tmp/mysql.sock is a symlink to /var/lib/mysql/mysql.sock but mysql directory doesn't exist in /var/lib.
After extensive research I didn't find how to "get" this directory.
I've found many entries in StackOverflow with the same title, I've tried almost all answer but none seems to work. especialy in my case I'm using brew and macOS ventura.
Typicaly for ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' the accepted answer is not about brew.
I've tried brew reinstall mysql.
I've tried as well mysql -h 127.0.0.1 -u root -p in this case the error is ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (61).
I've tried to run mysqld and then brew services start mysql, in this case I have the following error
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/502 /Users/CedMacBook1/Library/LaunchAgents/homebrew.mxcl.mysql.plist` exited with 5.
I've tried to change my password using sudo mysqladmin -u root password -p and once again I have the error error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'.
It looks like mysql is runningm, I've ran ps aux | grep mysqld and get the following line:
CedMacBook 21853 0,0 0,0 34400496 2728 s000 S+ 7:53 0:00.01 grep mysqld
Finally I've checked my /usr/local/etc/my.cnf and I have the following
# Default Homebrew MySQL server config
[mysqld]
socket=/tmp/mysql.sock
# Only allow connections from localhost
bind-address = 127.0.0.1
port=3306
mysqlx-bind-address = 127.0.0.1
At this stage I'd be happy to swipe out everything... if I could save all my database
Please help, I don't know what else to try
I have just installed xampp on Mac.
I was trying to import an existing .sql file to MySQL DB on phpMyAdmin.
It was a success.
But I cannot connect MySQL using mysql browser like Sequel Pro.
I think this is because of ERROR (2002)
This is the result when I type mysql on the terminal.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' (2 "No such file or directory")
Please help me how to fix this issue.
Have you checked it out here.
It means either the MySQL server is not installed/running, or the file mysql.sock doesn’t exist in /var/lib/mysql/.
There are a couple of solutions for this error.
First, check to see whether mysqld service is running or not. If not, start it:
service mysqld start
Then try to connect again.
Try to connect to 127.0.0.1 instead of localhost
If you connect to localhost, it will use the socket connector, but if you connect to 127.0.0.1 the TCP/IP connector will be used. So when the socket connector is not working, try connecting to 127.0.0.1 instead.
Edit file my.cnf
Find the file my.cnf (usually in /etc/) to edit and add these following line:
[mysqld]
socket=/var/lib/mysql/mysql.sock
[client]
socket=/var/lib/mysql/mysql.sock
Restart mysql and connect again.
Symlink
In some cases, you mysql.sock might be located in another folder. You have to find and symlink it. You might find it in /tmp/mysql.sock or /data/mysql_datadir/mysql.sock
For example, your file is located as in /tmp/mysql.sock
Then symlink it:
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
Restart mysql and connect again.
I'm using Linux and I recently downgraded MySQL to 5.6 from 5.7 (due to some issues because of its strictness). Now when I use command mysql, I get the error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I have checked several posts and systemctl mysql startseems to work. But everytime I reboot my system, I have to use systemctl mysql start again to start MySQL.
Also, service start mysql doesn't work.
There is no /etc/my.cnf file, only /etc/mysql/my.cnf file. I'm using Ubuntu 16.04.
How can I configure it so that the MySQL service starts at boot?
Edit:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
This post is unable to help either.
Basically, if mysql command is running without a host, it looks for a socket file on your local machine (this lets it connect to the running process directly). You have two workarounds. One is to include host in your mysql connection command mysql -u root -p -H 127.0.0.1, the other is to modify my.cnf to include:
[mysqld]
socket=/var/run/mysqld/mysqld.sock
[client]
socket=/var/run/mysqld/mysqld.sock
see here for more.
I'm getting the following error when trying to connect to MySQL through the command line (Ubuntu 14.04)
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Seems that the file /var/run/mysqld/mysqld.sock is missing. MySQL is still running
% sudo service mysql status
mysql start/running, process 42703
and I am able to connect with MySQLdb and sqlalchemy via Python and through MySQL Workbench and MySQL Pro. I was running a Python script and got the following error
(1053, 'Server shutdown in progress')
I restarted the script and everything ran like usual but since this point I have been unable to connect via command line. Not sure what happened or why the sock would disappear. I also ran
sudo find / -type s
and nothing related to MySQL is found.
UPDATE: Seems that someone uncommented bind-address = 127.0.0.1 (inside /etc/mysql/my.cnf), restarted the server, realized this was a mistake, put it back, and restarted. Would this remove the sock file?
Problem seems to be that multiple mysql processes are running. Try stopping mysql and mysqld processes followed by restarting mysql:
sudo pkill mysql
sudo pkill mysqld
sudo service mysql restart
now you should be able to log into mysql normally
mysql -u root -p
if it still doesn't work, and you're mysql database is local, try changing the bind-address from 127.0.0.1 to localhost before attempting to kill the processes like I showed you above.
Open up the configuration file:
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
look for the line containg bind-address and change the line to
bind-address = localhost
save the file and exit
now kill the processes and restart mysql ( first 3 steps in the beginning of this comment).
I have setup a MySQL 5.6 Server on an Ubuntu 14.04 Server distribution on Virtualbox, and am trying to connect to it via TCP/IP from the host Linux Mint 17 Desktop OS over the WAN.
Connection through the MySQL client on the VM works fine, but whenever a connection is attempted from the host machine (via mysql-client-5.6 package) an error comes back with one of 2 errors:
INPUT: $ mysql -u client -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
or
INPUT: $ mysql -u client -p protocol=tcp -h 127.0.0.1
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
Server Setup:
Fresh Ubuntu 14.04 Server installation with only mysql-server-5.6 and openssl packages installed from Ubuntu APT repository.
Users created are 'root'#'%' and 'client'#'%', both with full privileges given to them.
Iptables was modified to try and fix the issue (it came completely stripped) and shows: accept tcp connection from mysql and shows:
target: ACCEPT prot: tcp opt: -- source: anywhere destination: anywhere tcp dpt:mysql .
Configuration file "/etc/mysql/my.cnf" was hardly touched, only tried to change bind-address to values 127.0.0.1 , 0.0.0.0 , commented : all unsuccessful. Server and Client socket is set to 3306.
"service mysql status" returns output: "mysql start/running, process 10650"
Checked that tcp port 3306 is being listened to through "netstat -tulpn" command. returns output: PID=tcp6 Local Address=:::3306 Foreign Address=:::* State=LISTEN .
Client Setup:
Installed package mysql-client-5.6 from Ubuntu APT repository
All configurations are preset and untouched.
Would like an affirmation on the following: Was getting the idea that connecting through Unix socket is only possible through the OS hosting the server (internally), while any external OS has to use TCP/IP and so I tried the "protocol=tcp" bit in my 2nd input.
Was searching for a solution for over 2 days now, starting to feel really frustrated. Any useful help would be greatly appreciated!