9

A have already read everything about this error but I coundn't solve the problem.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38)

I'm trying to install mysql on my Mac OsX but when I try to connect to the db (mysql -u root -p) I see this problem, ERROR 2002.

I have Mysql installed in /usr/local/mysql

4
  • 1
    Have you checked that the mysqld process is running? Dec 19, 2012 at 13:25
  • When I write: mysql start, mysql gives me this error ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38) Dec 19, 2012 at 13:32
  • when I write /Library/StartupItems/MySQLCOM/MySQLCOM start It says Starting MySQL database server but in MYSQLPANEL on mac says: The mysql server instance is stopped. Dec 19, 2012 at 13:34
  • it's a bit tricky sometimes to start MySQL on Mac OS X, I've write you one possible way to do it, hope it helps. Dec 19, 2012 at 14:19

7 Answers 7

4

Check the MySQL daemon is running

You can check if the mysqld daemon from **Terminal Application* running:

ps -feax | grep mysqld 

And verifying that you get something similar to this:

    0  8308     1   0   0:00.08 ??         0:00.11 /bin/sh /usr/local/mysql/bin/mysqld_safe

or looking for a mysqld process on the Activity Monitor application

If it's not running you have to start the daemon.

Start MySQL daemon

On Mac OSX you can start the daemon from the Terminal Application with something like this:

sudo /usr/local/mysql/bin/mysqld_safe &

Again check that now the MySQL daemon is running as described before.

6
  • Ok a did this and now I have this: 0 8308 1 0 0:00.08 ?? 0:00.11 /bin/sh /usr/local/mysql/bin/mysqld_safe Dec 19, 2012 at 15:03
  • But still happen the same problem. There is 2 folders inside /usr/local/mysql: mysql/ and mysql-5.5.28-osx10.6-x86_64/. Is That a problem? Dec 19, 2012 at 15:05
  • @RafaelPontes if you can see that output from the ps command is that the daemon is running, try @RolandoMySQLDBA solution... you can also check the configuration file (usually /etc/my.cnf) and be sure the mysqld daemon is using that socket (/tmp/mysql.sock) Dec 19, 2012 at 19:32
  • Sorry, I thought that when I use sudo /usr/local/mysql/bin/mysqld_safe & it worked, but just now I saw this error: Dec 19, 2012 at 20:42
  • mysqld_safe Logging to '/var/lib/mysql/Rafaels-MacBook-Pro.local.err'. 121219 17:35:59 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 121219 17:36:03 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended Dec 19, 2012 at 20:42
10

You say you get the error when you run mysql -u root -p

This will look for a socket file to connect. When mysqld started up, it is possible for the socket file not to be made and still have mysqld start up ( See my post Percona-server time out on /etc/init.d/mysql start )

Try using one of the following to see if you can connect without a socket file

  • mysql -u root -p -h127.0.0.1
  • mysql -u root -p -h127.0.0.1 --protocol=tcp

If you can connect with one of these, the shutdown mysql like this

mysqladmin -u root -p -h127.0.0.1 --protocol=tcp shutdown

mysqld should shutdown properly. Afterwards, startup mysql as usual

Give it a Try !!!

2
  • finally i got my local mysql setup repaired! thats the solution for my problem here: serverfault.com/questions/987663/… Oct 9, 2020 at 12:45
  • I get this with the no-socket commands: ERROR 1045 (28000): Plugin caching_sha2_password could not be loaded: dlopen(/usr/local/Cellar/mariadb/10.4.6_1//usr/local/Cellar/mariadb/10.4.6_1/lib/plugin/caching_sha2_password.so, 2): image not found
    – trainoasis
    Mar 30, 2021 at 8:00
4

I know this is an older post, but I spent the last hour or so bouncing back and forth between serverfault, StackOverflow, and DataBase administrators trying to figure out how to solve this issue after installing on Mac (El Capitan) using homebrew.

At least in my case, the advice from this post worked:

# Run the following commands
mysqld stop
mysql.server start

From what I can gather, I think (at least in my case) brew mysql hadn't initialized the permanent socket and my network admin locked down the ability to connect new processes via /tmp/...

1

I am using MacOX El Capitan 10.11.3 and I faced the above issue and none of the answers worked independently. I then tried a combination of user153254 and Adam's and it worked like a charm!

mysqld stop
mysql.server start
mysql -u root

Avoiding mysql -u root -p did the trick

1

main reason is mariadb/mysql is not running.

brew services start mariadb

OR

brew services start mysql

I solved same issue in MariaDB with bellow command. restart MariaDB/MySQL

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist

I have installed MariaDB though homebrew. i have also restart my computer before running command.

enter image description here

2
  • nope, not working
    – trainoasis
    Mar 30, 2021 at 8:01
  • @trainoasis brew services start mariadb close your terminal and reopen and check Apr 1, 2021 at 10:18
0

I had the exact same problem and I searched every possible site for solution to such problem and was not be able to solve it. However, today I did a simple command line from the Mac's Terminal that is I just typed in mysql -u root and then it solved the problem for me.

Let me know if this solution helps.

0

Provide hostname along with username and password

mysql -u <username> -p<password> -h <yourhostname>

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .