Меню Рубрики

Error 2002 mysql mac os

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

На все запросы к MySQL выдает:

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

Перерыл все, ничего не помогает. Использую macOS Sierra.

1 ответ 1

Решение 1: Это проблема с разрешением /usr/local/mysql директории.

Решение 2: Вероятно, потому, что MySQL установлен, но еще не запущен.

Чтобы убедиться, что он запущен, откройте «Монитор активности» и в разделе «Все процессы» найдите и убедитесь, что вы видите процесс «mysqld».

Вы можете запустить его, установив «MySQL.prefPane».

Обычно я запускаю команду остановки и снова запускаю ее:

После в командной строке наберите mysql -uroot -ppassword

(root и password это я к примеру,если у вас отличаются то вводите свой )

если увидите строки на подобие «Welcom to the mysql monitore . » значит все работает корректно.

Install MySQL on Mac OS X: В самом конце показано как работать с ним после правильной установки


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

  • I am working on a Mac with OSX 10.10.3.
  • I have installed the PHP SDK for Google App Engine software.

Now I am trying to install MySQL server on my mac. I have downloaded the Mac OS X 10.9 (x86, 64-bit), Compressed TAR Archive here: http://dev.mysql.com/downloads/mysql/

As the tutorial says, I am command the following line in my Terminal:

First the terminal asked for my password, and when I enter this the following error occurs:

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

10 Answers 10

It’s a common error , you can fix it like this

You can remove root password with this command sequence:

Looks like Mysql server has not started.

Had exactly the same issue, used the above command to fix it.

OSX 10.13.2 High Sierra
mariadb 10.2.12

I got the exact same error when I tried to use mariadb , which I installed with homebrew. The first thing I did after installing was:

To troubleshoot, I did:

The solution:

The best instructions I found for manually starting and stopping mariadb are paradoxically at Starting and Stopping MariaDB Automatically:

You have the option of starting the mysqld server several different ways:

Run or invoke mysqld itself. An example of doing this is described more in Running MariaDB from the Source Directory.


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

I installed MySQL on Mac OS X Mountain Lion with homebrew install mysql , but when I tried mysql -u root I got the following error:

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

What does this error mean? How can I fix it?

27 Answers 27

It’s probably because MySQL is installed but not yet running.

To verify that it’s running, open up Activity Monitor and under «All Processes», search and verify you see the process «mysqld».

You can start it by installing «MySQL.prefPane».

You’ll need to start MySQL before you can use the mysql command on your terminal. To do this, run brew services start mysql . By default, brew installs the MySQL database without a root password. To secure it run: mysql_secure_installation .

To connect run: mysql -uroot . root is the username name here.

This happened after the homebrew install and occurs due to permission issues. The following commands fixed the issue.

Run: brew info mysql

And follow the instructions. From the description in the formula:

As others have pointed out this is because MySQL is installed but the service isn’t running. There are many ways to start the MySQL service and what worked for me is the below.

To start the service:

  1. Go to «System Preference»
  2. At the bottom pane there should be MySql icon.
  3. Double click that to launch the ‘MySQL Server Status’ and press the button ‘Start MySQL Server’

Mac Yosemite 10.10.3

Installed Package: /Volumes/mysql-advanced-5.6.24-osx10.8-x86_64

Solutions revolve around:

changing MySQL’s permissions

Starting a MySQL process

Just to add on a lot of great and useful answers that have been provided here and from many different posts, try specifying the host if the above commands did not resolve this issue for you, i.e

Warning — this method will remove all of your databases in the /usr/local/var/mysql folder

I had MySQL installed with Homebrew, and the only thing that fixed this for me was re-installing MySQL.

On my company laptop, I didn’t have permission to uninstall MySQL from my computer via Homebrew:

So instead, I removed and reinstalled MySQL manually:

Below I’m including the latest instructions from brew install mysql so newer searches for this issue can benefit:

In my case I loaded mysql now via launchctl load

/Library/LaunchAgents/homebrew.mxcl.mysql.plist and was then able to launch $ mysql and be on my way.

I hope this helps recent troubleshooters!

Looks like your mysql server is not started. I usually run the stop command and then start it again:

Same error, and this works for me.

This fixed my issue when I restarted the mysql service. Just run:

this problem related to /usr/local/var/mysql folder access, I remove this folder and reinstall mysql.

uninstall mysql with brew :

brew uninstall mysql

sudo rm -r /usr/local/var/mysql

  • brew install mysql@8.0
  • mysql -u root
  • This solution works fine for me! BUT YOU LOST ALL YOUR DATABASES! WARNING!

    Ough, that took me a while to figure out. I saw it in a comment. After installing mysql using brew, and starting the service (perhaps using sudo brew services start mysql ) then run:

    And MySQL should be running for your thereafter.

    For me it was simple as running:

    In my case it was simply a matter of deleting a lock file.

    I found the solution to my problem. It was indeed because my MySQL server was not running.

    It was caused by MySQL not being correctly set up on my machine, thus not being able to run.

    To remedy this, I used a script which installs MySQL on Mac OSX Mountain Lion, which must have installed missing files.

    Important Note: This script sets the root password as a randomly generated string, which it saves on the Desktop, so take care not to delete this file and to note the password. It also installs MySQL manager in your system preferences. I’m also not sure if removes any existing databases, so be careful about that.


    mysqli_connect error 2002 “No such file or directory” Mac OS 10.13.2

    I know questions related to this have been asked a zillion times on Stackoverflow and elsewhere, however, I can’t seem to zero in on a resolution.

    I am using a nearly fresh-out-of-the-box Macbook 13 running OS 10.13.6 High Sierra.

    My goal is to create a development environment with MAMP such that I can create dynamic webpages and I’d like to use Tableau for analytics drawing data out of MySQL.

    I have successfully installed and run MAMP — I have created a simple database using phpMyAdmin — and I have connected Tableau to this database successfully — this works very well.

    With that in operation, I shifted my attention to trying to run php from my browser. Entering «localhost» yielded the «It works!» result.

    All good so far but here is where things go off the rails: I cannot connect to MySQL via a php file using the following (****** = my root password) — filename: test_connect0.php:

    What returns from running Safari or Chrome — doesn’t matter — is the familiar issue: 2002 No such file or directory.

    BELIEVE ME, I have searched all over the internet for solutions and I believe I have tried each and everyone to no avail.

    Here are a few things I have done:

    1. Running phpInfo from MAMP returns the expected path to php.ini: /Applications/MAMP/bin/php/php7.2.1/conf
    2. In that php.ini file, the mysqli.default_socket is /Applications/MAMP/tmp/mysql/mysql.sock and that file does indeed exist
    3. Running phpInfo from MAMP indicates the php version is 7.2.1
    4. In /etc/apache2, I edited httpd.conf and uncommented LoadModule php7_module libexec/apache2/libphp7.so
    5. I have tried a number of different ways to run the test_connect0.php file: localhost/test_connect0.php localhost:3306/test_connect0.php

    An observation: In item 3 above, I noted that phpInfo from MAMP returns 7.2.1 as the version. When I run a phpinfo() script from the browser, however, it returns 7.1.16. I can’t explain why that’s a different php version and I cannot even FIND version 7.1.16 on my machine AND I’m not sure any of that really matters.

    To summarize, I have a functional MAMP and a functional Tableau connection to MAMP’s MySQL. What I can’t do is connect to MySQL from a php file run in the browser — I get the 2002 error.

    What other information can I provide to help zero in on a solution?


    Популярные записи