错误2002(hy000)。不能通过套接字'/var/run/mysqld/mysql.sock'连接到本地MySQL服务器(2)

我得到了这个错误

error 2002 (hy000):不能通过套接字'/var/run/mysqld/mysql.sock'连接到本地 MySQL 服务器(2)

尽管我已经成功地在ubuntu中通过命令行启动了mysql

mysql stop/waiting
mysql start/running, process 17691

然而,当试图访问网站时,我得到了一个数据库连接错误,以及在试图通过 "mysql -u root -p "访问mysql时出现的上述错误。

我检查了我的错误日志,我看到了这个

    131029 12:53:34 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be remo$
    131029 12:53:34 [Note] Plugin 'FEDERATED' is disabled.
    131029 12:53:34 InnoDB: The InnoDB memory heap is disabled
    131029 12:53:34 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    131029 12:53:34 InnoDB: Compressed tables use zlib 1.2.3.4
    131029 12:53:34 InnoDB: Initializing buffer pool, size = 26.0G
    131029 12:53:36 InnoDB: Completed initialization of buffer pool
    131029 12:53:36 InnoDB: highest supported file format is Barracuda.
    131029 12:53:38  InnoDB: Waiting for the background threads to start
    131029 12:53:39 InnoDB: 5.5.34 started; log sequence number 5146431500
    131029 12:53:39 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
    131029 12:53:39 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
    131029 12:53:39 [Note] Server socket created on IP: '0.0.0.0'.
    131029 12:53:39 [Note] Event Scheduler: Loaded 0 events
    131029 12:53:39 [Note] /usr/sbin/mysqld: ready for connections.
    Version: '5.5.34-0ubuntu0.12.04.1-log'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)

这是我第一次看到这个错误,我不知道如何解决这个问题,请你在这里帮助我一下。

谢谢

更新

好吧,我尝试了glglgl'的解决方案,在重新启动后,我在错误日志中得到如下信息。

    131029 13:17:36 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be remo$
    131029 13:17:36 [Note] Plugin 'FEDERATED' is disabled.
    131029 13:17:36 InnoDB: The InnoDB memory heap is disabled
    131029 13:17:36 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    131029 13:17:36 InnoDB: Compressed tables use zlib 1.2.3.4
    131029 13:17:36 InnoDB: Initializing buffer pool, size = 26.0G
    131029 13:17:38 InnoDB: Completed initialization of buffer pool
    131029 13:17:38 InnoDB: highest supported file format is Barracuda.
    131029 13:17:40  InnoDB: Waiting for the background threads to start
    131029 13:17:41 InnoDB: 5.5.34 started; log sequence number 5146431500
    131029 13:17:41 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
    131029 13:17:41 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
    131029 13:17:41 [Note] Server socket created on IP: '127.0.0.1'.  
    131029 13:17:41 [Note] Event Scheduler: Loaded 0 events
    131029 13:17:41 [Note] /usr/sbin/mysqld: ready for connections.
    Version: '5.5.34-0ubuntu0.12.04.1-log'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)

我的问题得到了解决,检查了Ubuntu 12.04上的进程是否正在运行。

ps ax | grep mysql

然后答案是它没有运行,所以我做了

sudo service mysql start

或尝试

sudo /etc/init.d/mysql start
评论(5)

我在系统上安装xampp时遇到了同样的问题。mysql服务器寻找/var/run/mysqld/mysqld.sock,但mysql.sock文件在xampp文件夹中,所以我使用了

 find / -name '*.sock'

来找到mysql.sock文件,然后用

ln -s  /var/run/mysqld/mysqld.sock

来获取*.sock文件的链接,然后试了试mysql,运行没有错误。 希望这能解决你的问题。

如果该目录不存在,请记得创建它。

评论(1)

如果你仔细观察,你就会发现其中的差别。

  • 服务器监听/var/run/mysqld/mysqld.sock
  • 客户端试图连接到/var/run/mysqld/mysql.sock

你必须调整其中的一个。

评论(2)