【问题标题】:Terminal mysql error 2002终端mysql错误2002
【发布时间】:2016-09-15 12:32:36
【问题描述】:

我使用 php 切换器和 phpmyadmin 自己安装 Apache/php/mysql。

在我修复它之前,我经常在 phpmyadmin 上遇到 2002 错误,将 pma 文件“pma/config.inc.php”中的主机从“localhost”更改为“127.0.0.1”。

在我的终端上,当输入 mysql 命令时,它总是返回我:

> mysql 

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

但如果我在本地 IP 地址 127.0.0.1 上强制使用 root 密码连接,它可以工作。请注意,在 Google Chrome 中,phpmyadmin 适用于 http://127.0.0.1/pmahttp://localhost/pma

终端:

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

在 /tmp 文件夹中,我有一个锁定的文件:

mysql.sock.lock

Apache 版本:

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

PHP 版本(记住我有一个 php 切换器),但它也不适用于其他版本:

> 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 状态:

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

感谢您帮助我进行了稳定的配置,无需再次安装 MAMP 或其他服务器配置软件。我希望能够在我的终端上使用 mysql 命令而不强制它,并且不再看到这个 2002 错误。

Ps : 抱歉第一次发法文

编辑:好的,似乎没有人知道为什么。但是,您可以为“mysql -u root -h 127.0.0.1 -p”创建一个别名。

【问题讨论】:

  • 欢迎来到 Stack Overflow!请为您的问题提供英文翻译。
  • En Anglais, s'il vous plait.
  • 我投票结束这个问题,因为它是法语的。
  • 很抱歉法国的帖子,现在没事了。
  • 不询问用户名和密码就想连接mysql吗?

标签: mysql


【解决方案1】:

尝试添加 ~/.my.cnf with

[client]
user=root
password=crazypasswordhere

也看到MySQL Utilities - ~/.my.cnf option file

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-25
    • 2015-01-23
    • 2017-09-07
    • 2021-06-14
    • 2012-07-13
    • 2017-07-08
    • 2012-12-20
    • 2012-08-15
    相关资源
    最近更新 更多