0

When tried to log in to the MySQL server yesterday I received the following error:

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

When I realised the server had been turned off I attempted to start it again and received the following error:

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

Below is the response from 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 sáb 2019-01-05 11:53:11 CET; 3s ago
  Process: 24667 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 24653 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 24667 (code=exited, status=1/FAILURE);         : 24668 (mysql-systemd-s)
    Tasks: 2
   Memory: 1.5M
      CPU: 244ms
   CGroup: /system.slice/mysql.service
           └─control
             ├─24668 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─24683 sleep 1

ene 05 11:53:11 james-Aspire-E5-571 systemd[1]: Starting MySQL Community Server...
ene 05 11:53:11 james-Aspire-E5-571 mysqld[24667]: 2019-01-05T10:53:11.441025Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000
ene 05 11:53:11 james-Aspire-E5-571 mysqld[24667]: 2019-01-05T10:53:11.441108Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 200
ene 05 11:53:11 james-Aspire-E5-571 mysqld[24667]: 2019-01-05T10:53:11.612971Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated.
ene 05 11:53:11 james-Aspire-E5-571 mysqld[24667]: 2019-01-05T10:53:11.615321Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.24-0ubuntu0.16.04.1-log) s
ene 05 11:53:11 james-Aspire-E5-571 mysqld[24667]: 2019-01-05T10:53:11.618519Z 0 [ERROR] Could not open file '/var/run/mysqld/mysqld.err' for e
ene 05 11:53:11 james-Aspire-E5-571 mysqld[24667]: 2019-01-05T10:53:11.618658Z 0 [ERROR] Aborting
ene 05 11:53:11 james-Aspire-E5-571 mysqld[24667]: 2019-01-05T10:53:11.618776Z 0 [Note] Binlog end
ene 05 11:53:11 james-Aspire-E5-571 mysqld[24667]: 2019-01-05T10:53:11.618879Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
ene 05 11:53:11 james-Aspire-E5-571 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
lines 1-24/24 (END)

And the response from journalctl -xe:

ene 05 11:54:42 james-Aspire-E5-571 systemd[1]: mysql.service: Unit entered failed state.
ene 05 11:54:42 james-Aspire-E5-571 systemd[1]: mysql.service: Failed with result 'exit-code'.
ene 05 11:54:42 james-Aspire-E5-571 systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
ene 05 11:54:42 james-Aspire-E5-571 systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysql.service has finished shutting down.
ene 05 11:54:42 james-Aspire-E5-571 systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysql.service has begun starting up.
ene 05 11:54:42 james-Aspire-E5-571 audit[24999]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/24999/status" p
ene 05 11:54:42 james-Aspire-E5-571 audit[24999]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/n
ene 05 11:54:42 james-Aspire-E5-571 audit[24999]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/24999/status" p
ene 05 11:54:42 james-Aspire-E5-571 kernel: audit: type=1400 audit(1546685682.938:11771): apparmor="DENIED" operation="open" profile="/usr/sbin
ene 05 11:54:42 james-Aspire-E5-571 kernel: audit: type=1400 audit(1546685682.938:11772): apparmor="DENIED" operation="open" profile="/usr/sbin
ene 05 11:54:42 james-Aspire-E5-571 kernel: audit: type=1400 audit(1546685682.938:11773): apparmor="DENIED" operation="open" profile="/usr/sbin
ene 05 11:54:43 james-Aspire-E5-571 audit[24999]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/run/mysqld/mysqld.e
ene 05 11:54:43 james-Aspire-E5-571 audit[24999]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/run/mysqld/mysqld.e
ene 05 11:54:43 james-Aspire-E5-571 audit[24999]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/run/mysqld/mysqld.e
ene 05 11:54:43 james-Aspire-E5-571 audit[24999]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/run/mysqld/mysqld.e
ene 05 11:54:43 james-Aspire-E5-571 audit[24999]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/run/mysqld/mysqld.e
ene 05 11:54:43 james-Aspire-E5-571 audit[24999]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/run/mysqld/mysqld.e
ene 05 11:54:43 james-Aspire-E5-571 mysqld[24999]: 2019-01-05T10:54:42.946027Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000
ene 05 11:54:43 james-Aspire-E5-571 mysqld[24999]: 2019-01-05T10:54:42.946094Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 200
ene 05 11:54:43 james-Aspire-E5-571 mysqld[24999]: 2019-01-05T10:54:43.124809Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated.
ene 05 11:54:43 james-Aspire-E5-571 mysqld[24999]: 2019-01-05T10:54:43.127236Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.24-0ubuntu0.16.04.1-log) s
ene 05 11:54:43 james-Aspire-E5-571 mysqld[24999]: 2019-01-05T10:54:43.130517Z 0 [ERROR] Could not open file '/var/run/mysqld/mysqld.err' for e
ene 05 11:54:43 james-Aspire-E5-571 mysqld[24999]: 2019-01-05T10:54:43.130653Z 0 [ERROR] Aborting
ene 05 11:54:43 james-Aspire-E5-571 mysqld[24999]: 2019-01-05T10:54:43.130771Z 0 [Note] Binlog end
ene 05 11:54:43 james-Aspire-E5-571 mysqld[24999]: 2019-01-05T10:54:43.130875Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
ene 05 11:54:43 james-Aspire-E5-571 kernel: audit: type=1400 audit(1546685683.126:11774): apparmor="DENIED" operation="mknod" profile="/usr/sbi
ene 05 11:54:43 james-Aspire-E5-571 kernel: audit: type=1400 audit(1546685683.126:11775): apparmor="DENIED" operation="mknod" profile="/usr/sbi
ene 05 11:54:43 james-Aspire-E5-571 kernel: audit: type=1400 audit(1546685683.126:11776): apparmor="DENIED" operation="mknod" profile="/usr/sbi
ene 05 11:54:43 james-Aspire-E5-571 kernel: audit: type=1400 audit(1546685683.126:11777): apparmor="DENIED" operation="mknod" profile="/usr/sbi
ene 05 11:54:43 james-Aspire-E5-571 kernel: audit: type=1400 audit(1546685683.126:11778): apparmor="DENIED" operation="mknod" profile="/usr/sbi
ene 05 11:54:43 james-Aspire-E5-571 kernel: audit: type=1400 audit(1546685683.126:11779): apparmor="DENIED" operation="mknod" profile="/usr/sbi
ene 05 11:54:43 james-Aspire-E5-571 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
lines 1465-1506/1506 (END)

According to a help article I read this error is caused by Apparmor not being configured properly.

The article states that the resolution to this problem is to add permissions reported by the error message to /etc/apparmor.d/usr.sbin.mysqld file. In this situation, it is required to add r permissions to /proc/*/status and /sys/devices/system/node/.

However, when I tried to do this I found that I was unable to edit the file.

I have tried to remove mysql (purging is not an option as I need to protect my databases) in order to re-install but I am given the response that the mysql package could not be located...

2
  • Stack Overflow is a site for programming and development questions. You should probably use another site on the Stack Exchange network for this question. If you feel the question is on-topic, then see How to create a Minimal, Complete, and Verifiable example.
    – user141074
    Commented Jan 5, 2019 at 17:27
  • "However, when I tried to do this I found that I was unable to edit the file." - were you using a root shell?
    – Philᵀᴹ
    Commented Jan 6, 2019 at 12:48

1 Answer 1

1

Please check that the mysql user can read/write on the /var/lib/mysql directory.

That directory should actually be owned by the mysql user.

I had a similar issue and the log pointed to an apparmor related issue, but in reality my problem was the /var/lib/mysql directory and its contents owned by root after restoring the MySql data directory from a backup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.