mysql_upgrade: Got error: 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) while connecting to the MySQL server

Bug #1605948 reported by Firmansyah on 2016-07-24
132
This bug affects 29 people
Affects Status Importance Assigned to Milestone
mysql-5.7 (Ubuntu)
High
Unassigned

Bug Description

After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up mysql-server-5.7 (5.7.13-0ubuntu0.16.04.2) ...
Renaming removed key_buffer and myisam-recover options (if present)
insserv: warning: current start runlevel(s) (empty) of script `mysql' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `mysql' overrides LSB defaults (0 1 6).
mysql_upgrade: Got error: 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) while connecting to the MySQL server
Upgrade process encountered error and will not continue.
mysql_upgrade failed with exit status 11
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                          Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

ProblemType: Package
DistroRelease: Ubuntu 16.04
Package: mysql-server-5.7 5.7.13-0ubuntu0.16.04.2
ProcVersionSignature: Ubuntu 4.4.0-24.43-generic 4.4.10
Uname: Linux 4.4.0-24-generic x86_64
ApportVersion: 2.20.1-0ubuntu2.1
Architecture: amd64
Date: Sun Jul 24 08:14:47 2016
ErrorMessage: subprocess installed post-installation script returned error exit status 1
InstallationDate: Installed on 2016-04-26 (88 days ago)
InstallationMedia: Ubuntu 16.04 LTS "Xenial Xerus" - Release amd64 (20160420.1)
Logs.var.log.daemon.log:

MySQLConf.etc.mysql.conf.d.mysql.cnf: [mysql]
MySQLConf.etc.mysql.conf.d.mysqldump.cnf:
 [mysqldump]
 quick
 quote-names
 max_allowed_packet = 16M
MySQLConf.etc.mysql.mysql.conf.d.mysqld_safe_syslog.cnf:
 [mysqld_safe]
 syslog
MySQLVarLibDirListing: ['auto.cnf', 'brm', 'ib_logfile0', 'ibdata1', 'sys', 'ib_buffer_pool', 'performance_schema', 'ib_logfile1', 'mysql', 'debian-5.7.flag']
ProcCmdline: BOOT_IMAGE=/boot/vmlinuz-4.4.0-24-generic.efi.signed root=UUID=1f7e918c-d6e9-41d4-b7fb-89decfb7104b ro quiet splash vt.handoff=7
RelatedPackageVersions:
 dpkg 1.18.4ubuntu1.1
 apt 1.2.12~ubuntu16.04.1
SourcePackage: mysql-5.7
Title: package mysql-server-5.7 5.7.13-0ubuntu0.16.04.2 failed to install/upgrade: subprocess installed post-installation script returned error exit status 1
UpgradeStatus: No upgrade log present (probably fresh install)

Firmansyah (firmanium) wrote :
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in mysql-5.7 (Ubuntu):
status: New → Confirmed

The Ubuntu QA process is really going downhill. First they break NTP, now they break MySQL. And this is in 16.04LTS, not even bleeding-edge !!

Setting up mysql-server-5.7 (5.7.13-0ubuntu0.16.04.2) ...
Renaming removed key_buffer and myisam-recover options (if present)
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for " for details.
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 mysql-server-5.7
E: Sub-process /usr/bin/dpkg returned an error code (1)

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: inactive (dead) (Result: exit-code) since Mon 2016-07-25 15:03:20 BST; 9min ago
 Main PID: 29823 (code=exited, status=0/SUCCESS)

Jul 25 15:03:19 XXXX systemd[1]: mysql.service: Unit entered failed state.
Jul 25 15:03:19 XXXX systemd[1]: mysql.service: Failed with result 'exit-code'.
Jul 25 15:03:20 XXXX systemd[1]: mysql.service: Service hold-off time over, scheduling restar
Jul 25 15:03:20 XXXX systemd[1]: Stopped MySQL Community Server.
Jul 25 15:03:20 XXXX systemd[1]: mysql.service: Start request repeated too quickly.
Jul 25 15:03:20 XXXX systemd[1]: Failed to start MySQL Community Server.

My mySQL was working perfectly well until today's upgrade.

Changed in mysql-5.7 (Ubuntu):
importance: Undecided → High
Robie Basak (racb) on 2016-08-02
summary: - package mysql-server-5.7 5.7.13-0ubuntu0.16.04.2 failed to
- install/upgrade: subprocess installed post-installation script returned
- error exit status 1
+ mysql_upgrade: Got error: 2002: Can't connect to local MySQL server
+ through socket '/var/run/mysqld/mysqld.sock' (2) while connecting to the
+ MySQL server
lpuzio (leszekpuzio) wrote :

Hi,

I had the same error. I solved this by one command:
sudo systemctl enable mysql

Than I had to start MySql:
sudo service mysql start

After this I was able to update:
sudo apt dist-upgrade

One could try to recreate this bug by disabling MySql before upgrade:
sudo systemctl disable mysql

I hope this helped you.

Regards,

Lyle (mamadontgodaddycomehome) wrote :

The workaround suggested by @lpuzio worked for me with the same problem. Thanks.

pickett.aaron (pickett-aaron) wrote :

I am having a issue with a new install of 16.04.01:

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

trsbox:~$ mysqladmin -u root -p status
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

trsbox:~$ sudo systemctl enable mysql
[sudo] password for scorch:
Synchronizing state of mysql.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install enable mysql

trsbox:~$ sudo 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.

trsbox:~$ 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 Fri 2017-02-17 12:54:34 EST; 17s ago
  Process: 4248 ExecStart=/usr/sbin/mysqld (code=exited, status=2)
  Process: 4244 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 4248 (code=exited, status=2); : 4249 (mysql-systemd-s)
    Tasks: 2
   Memory: 12.3M
      CPU: 730ms
   CGroup: /system.slice/mysql.service
           └─control
             ├─4249 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─4314 sleep 1

pickett.aaron (pickett-aaron) wrote :
Download full text (4.9 KiB)

And:

trsbox:~$ sudo journalctl -xe
Feb 17 13:01:41 trsbox.net audit[5682]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=5682 comm="mysqld" requested_mask="r"
Feb 17 13:01:41 trsbox.net audit[5682]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/5682/status" pid=5682 comm="mysqld" requested_mask="r" denied_
Feb 17 13:01:41 trsbox.net kernel: audit: type=1400 audit(1487354501.565:143): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/5682/status" pid=5682 comm=
Feb 17 13:01:41 trsbox.net kernel: audit: type=1400 audit(1487354501.565:144): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=56
Feb 17 13:01:41 trsbox.net kernel: audit: type=1400 audit(1487354501.565:145): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/5682/status" pid=5682 comm=
Feb 17 13:01:41 trsbox.net systemd[1]: mysql.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Feb 17 13:01:42 trsbox.net sshd[5648]: Failed password for root from 183.214.141.101 port 19744 ssh2
Feb 17 13:01:43 trsbox.net sshd[5652]: Failed password for root from 123.183.209.136 port 19999 ssh2
Feb 17 13:01:44 trsbox.net sshd[5652]: Received disconnect from 123.183.209.136 port 19999:11: [preauth]
Feb 17 13:01:44 trsbox.net sshd[5652]: Disconnected from 123.183.209.136 port 19999 [preauth]
Feb 17 13:01:44 trsbox.net sshd[5652]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=123.183.209.136 user=root
Feb 17 13:01:46 trsbox.net sshd[5648]: Failed password for root from 183.214.141.101 port 19744 ssh2
Feb 17 13:01:48 trsbox.net sshd[5648]: Failed password for root from 183.214.141.101 port 19744 ssh2
Feb 17 13:01:48 trsbox.net sshd[5648]: error: maximum authentication attempts exceeded for root from 183.214.141.101 port 19744 ssh2 [preauth]
Feb 17 13:01:48 trsbox.net sshd[5648]: Disconnecting: Too many authentication failures [preauth]
Feb 17 13:01:48 trsbox.net sshd[5648]: PAM 5 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=183.214.141.101 user=root
Feb 17 13:01:48 trsbox.net sshd[5648]: PAM service(sshd) ignoring max retries; 6 > 3
Feb 17 13:01:50 trsbox.net sshd[5729]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Feb 17 13:01:50 trsbox.net sshd[5729]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key
Feb 17 13:01:51 trsbox.net sshd[5729]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=183.214.141.101 user=root
Feb 17 13:01:52 trsbox.net sshd[5737]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Feb 17 13:01:52 trsbox.net sshd[5737]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key
Feb 17 13:01:53 trsbox.net sshd[5739]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Feb 17 13:01:53 trsbox.net sshd[5739]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key
Feb 17 13:01:53 trsbox.net sshd[5729]: Failed password for root from 183.214.141.101 port 47025 ssh2
Feb 17 13:01:54 trsbox.net sshd[5737]: pam_unix(sshd:auth): authenticati...

Read more...

kro (stiolbe) wrote :

The workaround suggested by @lpuzio doesn't seem to work on bash for windows

Melvin Williams (8-private) wrote :

@lpuzio workaround worked for me too

Jun Yamut (jun-yamut) wrote :

Getting this exact same error after updating today. The workaround suggested above does not fix this issue. I'm on 16.04.3.

Avi Schwartz (le-avion) wrote :

Getting the same error in today's update. @lpuzio work around did not work for me. 16.04.3.

Nick Weavers (nickweavers) wrote :

@lpuzio your workaround worked for me on bash for windows - many thanks!

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial

$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.

$ mysql --version
mysql Ver 14.14 Distrib 5.7.20, for Linux (x86_64) using EditLine wrapper

CKDevelop (craft) wrote :

The workaround proposed by @lpuzio worked for me with the same problem. Thank you.

[FR]
La solution de contournement proposée par @lpuzio a fonctionné pour moi avec le même problème. Merci.

[SHELL]
sudo systemctl enable mysql
sudo service mysql start
sudo apt dist-upgrade OR sudo dpkg -a --configure
sudo systemctl disable mysql

Noctis Bennington (noctis13) wrote :

I can confirm that the post of @lpuzio is true. Only you just need activate in systemctl to "enable" mysql and then the error doesn't appear.
Thanks @lpuzio.

felix (fegasi) wrote :

i read a solution in stack overflow that worked for me. i have changed the socket location to tmp/mysql.sock in my.cnf. So when the upgrade script searched for it, was not able to find it (dfault location was var/lib/mysql.sock). So i changed debian.cnf in //etc/mysql/ to the particular socket mysql server was actively running and voala!! everything worked perfect.. cheers...

Michael Mayaka (leyland1) wrote :

I can also confirm the workaround provided by @lpuzio works. Thanks so much @lpuzio!!! I have been looking for a fix for this error that keeps giving me unexpected downtime (all my sites use MySQL) and only just found this post by searching the error given by apt.

Zoltan Lippai (1-zoli) wrote :

#17 that solution worked for me as well. Thanks for suggesting it!

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers