5

I had MySQL running fine on my Mac till earlier today when I installed homebrew and also updated my Path.

When I try to run mysql from my ternimal window now, I get the following error:

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

I can't connect MySQLAdmin either.

I can't even run Mysqld. The error I get when trying to run mysqld is that it can't create test file.

I also tried to telnet localhost 3306 and wasn't able to connect.

Any help would be appreciated as I am fairly new to Mac.

OMG Ponies
  • 300,587
  • 73
  • 490
  • 482
Sohrab Hejazi
  • 1,291
  • 6
  • 16
  • 27
  • 1
    You should try asking this on http://superuser.com – Mitch Dempsey May 29 '10 at 01:45
  • What does your config file look like? Can you post the contents of your config file? The file is `my.cnf` and found in `/etc/`. When I had this problem, I renamed the config file and restarted the computer... things seemed to work better. Have you messed with the config file at all? – Hristo Jul 06 '10 at 14:35
  • Did any of the answers below solve your problem? If yes could you just accept one of them then? – T.Chmelevskij Oct 09 '16 at 15:18
  • @T.Chmelevskij - This question is from 6 years ago. I was fairly new to stackoverflow back then and unfortunately didn't mark the appropriate answer. I don't recall which answer helped me solve my problem. I suggest start by using the answers that have received the most amount of votes by fellow users. – Sohrab Hejazi Oct 10 '16 at 18:44

7 Answers7

8

Basically, all you have to do is:

  1. Go to "System Preferences"
  2. Then, if MySQL is installed you should see a "MySQL" icon in the "Other" section right at the bottom. Click on it.
    mac system preferences
  3. Click on "Start MySQL Server"
    mysql panel

You will now be able to start the MySQL command prompt without getting the "Can't connect..." error.

consuela
  • 1,646
  • 6
  • 22
  • 24
8

If it's homebrew installation try:

$ mysql.server start
T.Chmelevskij
  • 1,434
  • 13
  • 27
4

The mysql error (2002) is caused by the fact mysqld isn't running. The error you are seeing when starting mysqld is probably a permissions issue. Try starting mysqld as root or sudo'ing the command.

Paul
  • 41
  • 2
2

I'm user of osX 10.11.3 (El Capitan)

  1. first of all, check your mysql version.

    $ mysql --version
  2. check the server is already running.

    $ ps -ex | grep mysql

    If you checked this following string, that means mysql server is already running.

    => mysqld_safe / --pid-file=#{path}

    (The mysql pid file created when mysql server running to succeessfully. )

    In that case, you have to stop mysql server.

    $ mysql.server stop
  3. and start your mysql server

    $ mysql.server start

    Starting MySQL SUCCEESS!

  4. and start(or restart) your mysql server

    $ mysql.server start
    $ mysql.server restart

If you failed to start mysql server, please leave me error message when you run mysql.server start

jamy
  • 335
  • 2
  • 5
1
  1. Go to phpMyAdmin/config.inc.php edit the line $cfg['Servers'][$i]['password'] = ''; to $cfg['Servers'][$i]['password'] = 'yourpassword';

  2. And the last thing $cfg['Servers'][$i]['extension'] = 'mysql'; change this to $cfg['Servers'][$i]['extension'] = 'mysqli'; Now restart your server. and see .

This problem might occur due to setting of a password to root thus phpmyadmin is not able to connect to the mysql database.

Hemanta Nandi
  • 149
  • 1
  • 3
1

I know this question is old but I fix this doing those followings commands

cd /usr/local/mysql
sudo ./bin/mysqld_safe
my_mac_password

Ctrl + Z

bg

Ctrl + D

quit the terminal

The problem is that I have to do this each time I reboot my mac.

Source: http://openclassrooms.com/courses/administrez-vos-bases-de-donnees-avec-mysql/installation-de-mysql

John
  • 11
  • 1
1

It may also be that the address to your sock-file is wrong in php.ini.

Open up the terminal, and run the following:

netstat -ln | grep mysql

This will show the correct path to your socket. Check it versus the address in php.ini. If it's wrong, then correct it.

Kebman
  • 1,512
  • 1
  • 17
  • 31