Mac terminal ERROR 2002 (HY000): unable to connect to local MySQL server via socket '/tmp/mysql.sock' (2)

I am following this tutorial to set up my wordpress website in google cloud: https://googlecloudplatform.github.io/appengine-php-wordpress-starter-project/

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

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

As the tutorial says, I run the following line in my terminal:

/Users/myuser/Downloads/mysql-5.6.24-osx10.9-x86_64/bin/mysql/mysql -u root -p mypassword

      

The terminal first asked for my password and when I enter it the following error occurs:

ERROR 2002 (HY000): unable to connect to local MySQL server via socket '/tmp/mysql.sock' (2)

+4


source to share


9 replies


This is a common mistake, you can fix it like this:

enter image description here



You can remove the root password with this sequence of commands:

$ mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("") where User='root';
mysql> flush privileges;
mysql> quit

      

+3


source


It looks like the Mysql server is not running.

mysqld stop
mysql.server start

      



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

+21


source


OSX 10.13.2 High Sierra


mariadb 10.2.12

I got exactly the same error when I tried to use mariadb

which I installed along with homebrew. First thing I did after installation:

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

      

For troubleshooting, I did:

~$ which mysql
/usr/local/mysql/bin/mysql

      

and then I tried:

~$ mysql -u 7stud -p test
 Enter password:
 ERROR 2002 (HY000): Can't connect to local MySQL server 
 through socket '/tmp/mysql.sock' (2)

      

and:

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

      

Solution :

~$ mysql.server start
Starting MySQL
.180127 00:24:48 mysqld_safe Logging to '/usr/local/var/mysql/MyMBP.home.err'.
180127 00:24:48 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
 SUCCESS! 

~$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.5.5-10.2.12-MariaDB Homebrew

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

      

Ok let it go

mysql> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

mysql> CREATE DATABASE my_db;
Query OK, 1 row affected (0.00 sec)

mysql> use my_db;
Database changed

mysql> show tables;
Empty set (0.01 sec)

mysql> CREATE TABLE people (
    -> id INT(12) not null auto_increment primary key, 
    -> name VARCHAR(40), 
    -> info VARCHAR(100)
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql> describe people;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int(12)      | NO   | PRI | NULL    | auto_increment |
| name  | varchar(40)  | YES  |     | NULL    |                |
| info  | varchar(100) | YES  |     | NULL    |                |
+-------+--------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)

mysql> INSERT INTO people(name, info) VALUES("Joe", "a b c") ;
Query OK, 1 row affected (0.01 sec)

mysql> select * from people;
+----+------+-------+
| id | name | info  |
+----+------+-------+
|  1 | Joe  | a b c |
+----+------+-------+
1 row in set (0.00 sec)

mysql> INSERT INTO people(name, info) VALUES("Beth", "1 2 3") ;
Query OK, 1 row affected (0.00 sec)

mysql> select * from people;
+----+-------+-------+
| id | name  | info  |
+----+-------+-------+
|  1 | Joe   | a b c |
|  2 | Beth  | 1 2 3 |
+----+-------+-------+
2 rows in set (0.00 sec)

mysql> quit
Bye

~$ mysql.server stop
Shutting down MySQL
. SUCCESS! 
~$ 

      

The best instructions I've found for manually starting and stopping mariadb paradoxically when starting and stopping MariaDB automatically :

You have the option to start the mysqld server in several different ways:

  1. Start or call mysqld itself. An example of this is described in the section Starting MariaDB from a source directory.

  2. Use the mysqld_safe startup script

  3. Use the mysql.server startup script

The mysql.server script starts mysqld by first navigating to the MariaDB installation directory and then calling mysqld_safe. Adding the appropriate user row to the [mysqld] group in your my.cnf file will start the server as that user.

If you have installed MariaDB in a non-standard location, you may need to edit the mysql.server script for it to work correctly.

mysql.server works like a standard SysV style init script. So you are using a script with start and stop arguments, for example:

mysql.server start
mysql.server stop

      

+5


source


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

How I solved this on my MAC + MAMP (pro) setup:

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

Which creates a symlink from /tmp/mysql.sock in MAMP mysql.sock

Now restart MAMP and then the error shouldn't appear again.

+4


source


If you installed Mysql through Homebrew, just run the command below, it will be helpful.

Brew MySQL startup services

+1


source


You can try to switch MySQL version.

Below are instructions for using HomeBrew on a Mac.

First, list all versions of mysql:

$ brew list --versions mysql 

      

Switch to old version:

$ brew services stop mysql
$ brew switch mysql 5.7.20
$ brew services start mysql

      

+1


source


yes it works for me too .... but I don't understand: in both php.ini conf files (apache and php MAMP) the socket path is good: socket=/Applications/MAMP/tmp/mysql/mysql.sock

so why search /tmp/mysql.sock

???

Thanks to everyone who can "eclairer ma lanterne!"

0


source


This work for me, just delete the file $ rm/tmp/mysql.sock

then$ brew services mariadb restart

0


source


Before doing anything drastic, try connecting using the loopback address 127.0.0.1

instead localhost

of the default.

mysql -h 127.0.0.1 -u root -p

      

The localhost

default name , if you do not specify -h

, connects over named pipes, not TCP / IP. This is the error message you see if named pipes are not enabled.

0


source







All Articles