Ubuntu 17.10 - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysq

Posted

技术标签:

【中文标题】Ubuntu 17.10 - ERROR 2002 (HY000): Can\'t connect to local MySQL server through socket \'/var/run/mysqld/mysqld.sock\' (2)【英文标题】:Ubuntu 17.10 - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)Ubuntu 17.10 - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 【发布时间】:2018-08-01 19:51:53 【问题描述】:

我看到有人在堆栈溢出时提出类似的问题,但似乎没有一个能正确解决我的问题。我最近将我的系统从 Ubuntu 16.04 升级到 Ubuntu 17.10 。从那以后,我一直遇到 mysql 的问题,我无法正常启动它并显示以下错误:

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

我在网上搜索了许多解决方案,最后还尝试卸载并重新安装,但几天或几次尝试后问题又出现了。运行“service mysql start”,显示:

Job for mysql.service failed because the control process exited with 
error code.
See "systemctl  status mysql.service" and "journalctl  -xe" for 
details.

在运行建议的命令时,它会显示以下日志:

systemctl status mysql.service

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor 
preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Thu 2018-
02-22 09:06:31 IST; 4s ago
  Process: 8936 ExecStart=/usr/sbin/mysqld (code=exited, 
status=1/FAILURE)
  Process: 8930 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre 
(code=exited, status=0/SUCCESS)
 Main PID: 8936 (code=exited, status=1/FAILURE); Control PID: 8937 
(mysql-systemd-s)
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/mysql.service
           └─control
             ├─8937 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─8948 sleep 1

Feb 22 09:06:31 vamshi-Lenovo-G50-70 systemd[1]: Starting MySQL 
Community Server...
Feb 22 09:06:32 vamshi-Lenovo-G50-70 mysqld[8936]: 2018-02-
22T03:36:31.948822Z 0 [Warning] Changed limits: max_open_files: 1024 
(requested 5000)
Feb 22 09:06:32 vamshi-Lenovo-G50-70 mysqld[8936]: 2018-02-
22T03:36:31.948879Z 0 [Warning] Changed limits: table_open_cache: 431 
(requested 2000)
Feb 22 09:06:32 vamshi-Lenovo-G50-70 mysqld[8936]: 2018-02-
22T03:36:32.126417Z 0 [Warning] TIMESTAMP with implicit DEFAULT value 
is deprecated. Please use --explicit_def
Feb 22 09:06:32 vamshi-Lenovo-G50-70 mysqld[8936]: 2018-02-
22T03:36:32.128149Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.21-
0ubuntu0.17.10.1) starting as process 8936 ...
Feb 22 09:06:32 vamshi-Lenovo-G50-70 mysqld[8936]: 2018-02-
22T03:36:32.130652Z 0 [ERROR] Could not open file 
'/var/log/mysql/error.log' for error logging: No such file o
Feb 22 09:06:32 vamshi-Lenovo-G50-70 mysqld[8936]: 2018-02-
22T03:36:32.130675Z 0 [ERROR] Aborting
Feb 22 09:06:32 vamshi-Lenovo-G50-70 mysqld[8936]: 2018-02-
22T03:36:32.130694Z 0 [Note] Binlog end
Feb 22 09:06:32 vamshi-Lenovo-G50-70 mysqld[8936]: 2018-02-
22T03:36:32.130750Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
Feb 22 09:06:32 vamshi-Lenovo-G50-70 systemd[1]: mysql.service: Main 
process exited, code=exited, status=1/FAILURE

journalctl -xe
Feb 22 09:11:21 vamshi-Lenovo-G50-70 gnome-shell[2902]: 
[AppIndicatorSupport-WARN] Attempting to re-register 
:1.69/org/ayatana/NotificationItem/multiload; resetting inst
Feb 22 09:11:21 vamshi-Lenovo-G50-70 gnome-shell[2902]: 
[AppIndicatorSupport-WARN] Item 
:1.69/org/ayatana/NotificationItem/multiload is already registered
 ESCOD

每次发生这种情况,我都会卸载 mysql 并重新安装(服务器而不是客户端),然后它在最初的几次尝试中工作正常,然后又回到相同的情况。提前致谢!

ls -al
total 32824
drwxrwxr-x  8 root   syslog     4096 Feb 22 08:44 .
drwxr-xr-x 14 root   root       4096 Feb 16  2017 ..
-rw-r--r--  1 root   root       1527 Feb 17 08:58 alternatives.log
-rw-r-----  1 root   adm           0 Feb 22 08:44 apport.log
-rw-r-----  1 root   adm         486 Feb 21 07:29 apport.log.1
-rw-r-----  1 root   adm         455 Feb 20 20:54 apport.log.2.gz
-rw-r-----  1 root   adm         514 Feb 19 21:42 apport.log.3.gz
-rw-r-----  1 root   adm         758 Feb 19 18:15 apport.log.4.gz
-rw-r-----  1 root   adm         459 Feb 17 23:07 apport.log.5.gz
-rw-r-----  1 root   adm        1389 Feb 16 00:33 apport.log.6.gz
-rw-r-----  1 root   adm         275 Feb 14 20:16 apport.log.7.gz
drwxr-xr-x  2 root   root       4096 Feb 17 08:55 apt
-rw-r-----  1 syslog adm       86558 Feb 22 09:17 auth.log
-rw-r-----  1 syslog adm       97522 Feb 18 18:02 auth.log.1
-rw-------  1 root   utmp          0 Feb 14 20:17 btmp
drwxr-x---  2 root   lp         4096 Feb 22 08:44 cups
drwxr-xr-x  2 root   root       4096 Feb  5 14:51 dist-upgrade
-rw-r--r--  1 root   root      30036 Feb 17 08:58 dpkg.log
drwx--x--x  2 root   gdm        4096 Feb 14 20:18 gdm3
-rw-r--r--  1 root   root       2136 Feb 22 08:39 gpu-manager.log
-rw-r-----  1 syslog adm     3745433 Feb 22 09:28 kern.log
-rw-r-----  1 syslog adm     2302923 Feb 18 18:07 kern.log.1
-rw-rw-r--  1 root   utmp          0 Feb 14 20:17 lastlog
-rw-r-----  1 syslog adm         657 Feb 22 08:40 mail.log
-rw-r-----  1 syslog adm        1971 Feb 18 15:31 mail.log.1
-rw-r-----  1 syslog adm     3706136 Feb 22 09:28 syslog
-rw-r-----  1 syslog adm    18760212 Feb 22 08:44 syslog.1
-rw-r-----  1 syslog adm      989385 Feb 21 07:07 syslog.2.gz
-rw-r-----  1 syslog adm      587416 Feb 20 09:09 syslog.3.gz
-rw-r-----  1 syslog adm      593456 Feb 19 18:21 syslog.4.gz
-rw-r-----  1 syslog adm      672682 Feb 18 18:07 syslog.5.gz
-rw-r-----  1 syslog adm      166575 Feb 17 09:09 syslog.6.gz
-rw-r-----  1 syslog adm      891827 Feb 16 00:44 syslog.7.gz
-rw-r-----  1 syslog adm      572158 Feb 22 09:28 ufw.log
-rw-r-----  1 syslog adm      234885 Feb 18 18:06 ufw.log.1
drwxr-xr-x  2 root   root       4096 Feb 15 22:00 unattended-upgrades
drwxr-xr-x  2 root   root       4096 Feb 22 08:40 vmware
-rw-rw-r--  1 root   utmp      20736 Feb 22 08:41 wtmp

【问题讨论】:

查看 /var/log/mysql,使用“ls -al”。你得到了什么? 我得到一个目录列表,主要是 apport.log、apport.log.1 apport.log.2.gz 等等... 你能在你的问题中显示出来吗? @GerardH.Pille 我已经更新了我的问题,看看吧。 那不是/var/log/mysql,是吗?不存在?? 【参考方案1】:

创建文件夹 /var/log/mysql 并确保 mysqld 可以写入。

【讨论】:

嗯,我不知道。既然你问了,也许这会在尝试几次后再次发生。 检查 logrotate。 我在 /var/log/mysql 中尝试过 logrotate error.log,但它什么也没显示。 如果您启动您不知道的命令,可能会损害您的系统。例如。要启动 logrotate,你必须给它一个配置。 “logrotate /etc/logrotate.conf”。我相信您可以添加“-verbose”选项。 又出现了,/var/log下的mysql目录不见了。它从创建一个新的开始,但我不想要一个永久的解决方案。

以上是关于Ubuntu 17.10 - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysq的主要内容,如果未能解决你的问题,请参考以下文章

告别 Unity,Ubuntu 17.10 启用 GNOME

Ubuntu 17.10新爆点!

Problemxampp in ubuntu下命令行启动mysql报错: ERROR 2002 (HY000): Can't connect to local MySQL server t(代

Wayland被Ubuntu 17.10看上了

[图文] Ubuntu 17.10 已经发布,看看新功能

这是Ubuntu 17.10默认壁纸