5

I wanted to check out my logserver again, but all of sudden i get this message when i visit the url:

I am running on ubuntu xenial

FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php'

when i do journalctl -xe i get the following message:

-- Unit mysql.service has begun starting up.
Jun 15 19:26:12 arjanlog audit[3665]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/3665/status" pid=3665 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=112 ouid=112

Jun 15 19:26:12 arjanlog audit[3665]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=3665 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=112 ouid=0

Jun 15 19:26:12 arjanlog audit[3665]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/3665/status" pid=3665 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=112 ouid=112
Jun 15 19:26:12 arjanlog kernel: audit: type=1400 audit(1497547572.504:69): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" 
name="/proc/3665/status" pid=3665 comm="mysqld" requested_mask="r" denied_m

Jun 15 19:26:12 arjanlog kernel: audit: type=1400 audit(1497547572.504:70): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=3665 comm="mysqld" requested_mask="r"

Jun 15 19:26:12 arjanlog kernel: audit: type=1400 audit(1497547572.504:71): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/3665/status" pid=3665 comm="mysqld" requested_mask="r" denied_m

Jun 15 19:26:12 arjanlog systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Cœur
  • 37,241
  • 25
  • 195
  • 267
Arjan
  • 73
  • 1
  • 1
  • 6

7 Answers7

9

I had this problem too and solved it by fixing the apparmor configuration file at /etc/apparmor.d/usr.sbin.mysqld. I added these lines:

  /proc/*/status r,
  /sys/devices/system/node/ r,
  /sys/devices/system/node/node0/meminfo r,

Your journalctl -xe output shows the files MySQL needs permission to use. You can also look in /var/log/syslog:

Jun 15 19:26:12 arjanlog audit[3665]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/3665/status" pid=3665 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=112 ouid=112
Jun 15 19:26:12 arjanlog audit[3665]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=3665 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=112 ouid=0
Jun 15 19:26:12 arjanlog audit[3665]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/3665/status" pid=3665 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=112 ouid=112

That means that /usr/sbin/mysqld was DENIED trying to open /proc/3665/status and /sys/devices/system/node/ for reading (r).

Note that in the apparmor config file the trailing slash in /sys/devices/system/node/ is necessary, so don't leave it off!

Paul A Jungwirth
  • 23,504
  • 14
  • 74
  • 93
  • For me, this removed the error messages, but MySQL still failed to start. I finally look at the MySQL error log (e.g., `/var/log/mysql/error.log`) and noticed errors allocating memory for MySQL (e.g., ` InnoDB: Cannot allocate memory for the buffer pool`). Turns out, my EC2 instance didn't have a swap drive. I followed the instructions here to create one and MySQL started right up: https://stackoverflow.com/questions/10284532/amazon-ec2-mysql-aborting-start-because-innodb-mmap-x-bytes-failed-errno-12 – Jesse Hogan Feb 09 '19 at 16:11
2

It may not be necessary to stop apparmor entirely. It should be sufficient brute force to disable apparmor for mysqld, if you don't want to track down the core issue:

ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/usr.sbin.mysqld

i3i5i7
  • 130
  • 1
  • 2
  • 8
1

For me the error was that the mysql database got corrupted. I could see that when I went to logs /var/log/mysql/error.log and it showed an error:

InnoDB: Database was not shutdown normally!

There were some solutions out there which someone could use like table corruption issue

But it didn't work for me as I wasn't able to start a server in WRITE mode in order to solve the issue.

I managed to solve the issue by creating a copy of directory /var/lib/mysql - I copied to mysql.old and then deleted the mysql directory.

Then I called a command in terminal:

sudo mysqld --initialize --initialize-insecure

To generate a new mysql directory

I have then changed permissions of new directory by changing the user and group of mysql directory to user: mysql and group: mysql. Use chown command:

sudo chown -R mysql:mysql /var/lib/mysql

Then I called command:

sudo mysql -u root

and changed password with:

SET PASSWORD FOR root@'localhost' = PASSWORD('newpassword');

And then restarted mysql server:

sudo service mysql restart

And everything worked.


Some of the commands that I have used along the way were (although not sure how much they contributed to fixing the issue):

sudo apt-get --reinstall install mysql-server-5.7
Aleks
  • 4,866
  • 3
  • 38
  • 69
  • I had to disable the mysql profile for apparmor first, else it wouldnt let me reinit mysql. – paskl May 15 '18 at 07:39
1

I read in another SO thread comment that the apparmor="DENIED" message probably isn't the reason that MySQL (or in my case MariaDB) wasn't starting, as it's only a warning.

In my case updating and upgrading apt-installed packages and rebooting the system solved the problem.

sudo apt-get dist-upgrade
sudo apt-get update
sudo apt-get upgrade
sudo reboot

Then you'll need to wait a few minutes while the system restarts and log back in and restart the service(s) with either service, systemctl and I think possibly /etc/system.d.

Then MariaDB was chugging away happily.

There's a good post on the various apt upgrade commands here, and I think that what update does is update the source lists.

I had found this command useful as well, when there were no log files in /var/log/mysql:

tail -f /var/log/syslog | grep mysql
abu_bua
  • 1,361
  • 17
  • 25
MikeiLL
  • 6,282
  • 5
  • 37
  • 68
0

I got this bug when I tried to move mysql file from /var/lib/mysql to somewhere else.

add config to /etc/apparmor.d/usr.sbin.mysqld didn't work for me

then i got this bug for ubuntu

it said:

sudo nano /etc/apparmor.d/usr.sbin.mysqld
line 25 after:
# Allow config access
  /etc/mysql/** r,
-add line:
  /etc/mysql/* r,

and it works for me:

add /etc/mysql/* r, to /etc/apparmor.d/usr.sbin.mysqld

run systemctl restart apparmor.service

and service mysql start

yey
  • 1
0

After I followed the instructions given in https://stackoverflow.com/a/45986591 I was still not able to make the MySql server run. I checked its logs via tail -30 /var/log/mysql/error.log . This line caught my attention 2019-05-21T04:46:03.462807Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool. By reading the previous line of code, I was that it was trying to allocate 128MB of memory. Then I checked my Memory status and it was only 111 Mb free. I stopped few programs (node servers) and restarted the MySql and it started working. Then i commented all the AppArmor entries I had entered and restarted AppArmor and MySql. MySql started without any errors. So I could conclude that MySql was not getting enough memory to get started.

-3

solved by : sudo service apparmor teardown

Arjan
  • 73
  • 1
  • 1
  • 6