Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am following this tutorial to setup a Wordpress website on 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 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:

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

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)

like image 694
Robbert Avatar asked May 07 '15 11:05

Robbert


2 Answers

Looks like Mysql server has not started.

mysqld stop
mysql.server start

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

like image 64
Prakhar Agarwal Avatar answered Sep 22 '22 08:09

Prakhar Agarwal


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:

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

To troubleshoot, 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) 

The 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>

Okay, let's 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 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:

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

  2. Use the mysqld_safe startup script

  3. Use the mysql.server startup script

The mysql.server script starts mysqld by first changing to the MariaDB install directory and then calling mysqld_safe. Adding an appropriate user line to the [mysqld] group in your my.cnf file will cause the server to be run as that user.

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

mysql.server works as a standard SysV-style init script. As such you use the script with start and stop arguments like so:

mysql.server start
mysql.server stop
like image 25
7stud Avatar answered Sep 21 '22 08:09

7stud