mysqlubuntu-16.04ubuntu-17.10mysql-error-2002

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


I've seen similar questions being asked on stack overflow but none of them seem to solve my issue properly. I have recently upgraded my system from Ubuntu 16.04 to Ubuntu 17.10 . Since then, I've been experiencing a problem with mysql where I'm not able to start it up properly and it shows the following error:

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

I've searched for many solutions online and as a last effort also tried uninstalling and reinstalling but the problem resurfaces after a few days or few attempts. Upon running "service mysql start", it shows:

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

Upon running the suggested commands it shows the following logs:

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

Every time this happens, I uninstall mysql and reinstall(server not client), and then it works alright for the first few attempts, then it goes back to same situation. Thanks in advance!

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

Solution

  • Create folder /var/log/mysql and make sure mysqld can write to it.