简体   繁体   中英

Terminal mysql error 2002

I do my own installation Apache/php/mysql with a php switcher and phpmyadmin.

I often had an 2002 error on phpmyadmin before I fix it changing the host in the pma file 'pma/config.inc.php' from 'localhost' to '127.0.0.1'.

On my terminal, when typing mysql command, it is always returning me :

> mysql 

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

But if I force connecting with the root password, on the local IP adress 127.0.0.1, it works. Note that in Google Chrome, phpmyadmin works on http://127.0.0.1/pma and http://localhost/pma .

Terminal :

> mysql -u root -h 127.0.0.1 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.12 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>

In the /tmp folder I have one locked file :

mysql.sock.lock

Apache version :

> apachectl -v
Server version: Apache/2.4.18 (Unix)
Server built:   Feb 20 2016 20:03:19

PHP version (remember that I have a php switcher), but it doesn't work with other versions also :

> php -v
PHP 7.0.6 (cli) (built: Apr 29 2016 04:21:39) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

mysql status :

mysql  Ver 14.14 Distrib 5.7.12, for osx10.11 (x86_64) using  EditLine wrapper

Connection id:      4
Current database:
Current user:       root@localhost
SSL:            Not in use
Current pager:      less
Using outfile:      ''
Using delimiter:    ;
Server version:     5.7.12 MySQL Community Server (GPL)
Protocol version:   10
Connection:     127.0.0.1 via TCP/IP
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
TCP port:       3306
Uptime:         1 day 3 hours 28 min 19 sec

Threads: 1  Questions: 9  Slow queries: 0  Opens: 105  Flush tables: 1  Open tables: 98  Queries per second avg: 0.000

Thank you for helping me to have a stable configuration, without installing again MAMP or other server configuration software. I want to be able to use mysql command on my terminal without forcing it, and stop seeing this 2002 error.

Ps : sorry for the first post in french

EDIT : Okay , it seems no one know why. However you can make an alias for "mysql -u root -h 127.0.0.1 -p".

Try adding a ~/.my.cnf with

[client]
user=root
password=crazypasswordhere

also seen MySQL Utilities - ~/.my.cnf option file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM