2

I have been setting up a new laptop for development purposes and when trying to get MySQL to run in the Terminal I get the following message:

$ mysql -u root -p

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

Can somebody please help me out here?

Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
  • I've tried looking up answers from other posts but so far everything I have tried has failed. When I looked at the my.conf file I found the information mysql listed as: `[mysqld] user = mysql port=3306 socket = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock skip-external-locking key_buffer = 16M max_allowed_packet = 64M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 1M read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M tmpdir = /Applications/XAMPP/xamppfiles/temp/` – Nick Harmon Oct 29 '16 at 16:28
  • can upost whats inside mysql.socket ? – akash raigade Oct 29 '16 at 16:31
  • socket = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock – Nick Harmon Oct 29 '16 at 17:06
  • Also, I just tried running the mysql command again in terminal and now got this error: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) – Nick Harmon Oct 29 '16 at 17:37
  • Why are you using XAMPP? [Homebrew](http://brew.sh) is a much better tool for installing and managing databases like MySQL. XAMPP is intended for environments like Windows where that sort of thing is a giant pain to get working correctly. `brew install mysql` is not hard by comparison. – tadman Oct 29 '16 at 19:29
  • Im very new to using the command line and apparently I already have installed it as well via brew. Could that be whats causing the problem? How do I access mysql after installing it? – Nick Harmon Oct 29 '16 at 19:35
  • As you are using xampp can u access PHPMYADMIN ? – akash raigade Oct 29 '16 at 21:03
  • Possible duplicate of [MySQL - Mac - Error 2002 - Can't connect to local... through socket](http://stackoverflow.com/questions/2933415/mysql-mac-error-2002-cant-connect-to-local-through-socket) – Konstantinos Kamaropoulos Oct 30 '16 at 09:44
  • I have fixed it, it was due to multiple mysql instances installed. Thank You all for the help! – Nick Harmon Oct 31 '16 at 20:18

1 Answers1

1

You may get this error because mysql server is not started. For me it solved only by starting mysql server.

  1. to start Mysql server (for Mac OS X), command line in terminal:

    sudo /usr/local/mysql/support-files/mysql.server start

  2. or, simply go to your Mac System Preference --> MySQL --> click on start mysql..

Community
  • 1
  • 1
mOna
  • 2,341
  • 9
  • 36
  • 60