Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I am trying to run mysql client on my terminal. I have installed the latest mysql gem.

 ➜  ~ git:(master) ✗ ruby -v     ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]     ➜  ~ git:(master) ✗ rails -v     Rails 2.3.14     ➜  ~ git:(master) ✗ which mysql     mysql: aliased to nocorrect mysql     ➜  ~ git:(master) ✗ which ruby     /usr/bin/ruby     ➜  ~ git:(master) ✗ which rails     /usr/bin/rails     ➜  ~ git:(master) ✗ gem list  *** LOCAL GEMS ***  actionmailer (2.3.14) actionpack (2.3.14) activerecord (2.3.14) activeresource (2.3.14) activesupport (2.3.14) builder (2.1.2) bundler (1.0.21) capistrano (2.9.0) capybara (0.3.9) cgi_multipart_eof_fix (2.5.0) childprocess (0.2.2) columnize (0.3.4, 0.3.3) cucumber (0.9.4) cucumber-rails (0.3.2) culerity (0.2.15) daemons (1.1.4) database_cleaner (0.6.7) diff-lcs (1.1.3) expertiza-authlogic (2.1.6.1) fastercsv (1.5.4) fastthread (1.0.7) ffi (1.0.10, 1.0.9) gdata (1.1.2) gem_plugin (0.2.3) gherkin (2.2.9) highline (1.6.2) hoptoad_notifier (2.4.11) json (1.4.6) json_pure (1.6.1) linecache (0.46) mime-types (1.16) mongrel (1.1.5) mysql (2.8.1) mysql2 (0.3.7) net-scp (1.0.4) net-sftp (2.0.5) net-ssh (2.2.1) net-ssh-gateway (1.1.0) nokogiri (1.5.0) rack (1.1.2) rack-test (0.6.1) rails (2.3.14) rake (0.9.2) rbx-require-relative (0.0.5) rdoc (3.11) RedCloth (4.2.8) rgl (0.4.0) ruby-debug (0.10.4) ruby-debug-base (0.10.4) rubyzip (0.9.4) selenium-webdriver (2.8.0, 2.7.0) stream (0.5) term-ansicolor (1.0.7, 1.0.6)  ➜  expertiza git:(master) ✗ sudo su Password: sh-3.2# mysql -u root -p Enter password:  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) sh-3.2#  

I am not able to get rid of the above error. I have created a mysql.sock file in /Users/HPV/expertiza/tmp/sockets. In the file I have written mysql.default_socket =/expertiza/tmp/sockets/mysql.sock.

What am I doing wrong?

Thanks!

like image 611
Ava Avatar asked Oct 21 '11 00:10

Ava


People also ask

Can not connect to local mysql server through socket '/ tmp mysql sock?

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. Then try to connect again.

Can't connect to local mysql server through?

normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.

Can't connect to local server through socket?

Solution #2: Connect with 127.0. Another possible solution to the >can't connect to local mysql server through socket> error message is to try and connect to the MySQL using the 127.0. 0.1 ip address instead of localhost. When you use localhost to connect to MySQL, the operating system uses the socket connector.


2 Answers

You need to follow the directions to install and start the server.

The command varies depending on how you installed MySQL. Try this first:

sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

If that fails:

cd /usr/local/mysql
sudo ./bin/mysqld_safe
(Enter your password, if necessary)
(Press Control-Z)
bg

like image 88
David Schwartz Avatar answered Oct 08 '22 02:10

David Schwartz


Also, if you got this error and installed mysql via Homebrew, I found that this works (though you need to change "5.6.12" to your own version):

/usr/local/Cellar/mysql/5.6.12/bin/mysql.server restart

I just created a file ~/restartMysql.sh in my home directory (with only the line above in it) so that I can just use this whenever MySQL is acting up

like image 31
smckee Avatar answered Oct 08 '22 02:10

smckee