4

Changes I make to my.cnf don't seem to have any effect on the mysql environment. Here's a summary of what's happened...

I installed mysql 5.7 on Ubuntu 16.04 but then realized I needed to downgrade to mysql 5.6 due to incompatibility issues.

I apt purged the related applications and then removed any remaining directories such at /etc/mysql and /var/lib/mysql

I then installed mysql-5.6 (server and client) and related packages.

I was able to load one database from a dump from a server also running mysql 5.6 but when I tried to load a second database from a second dump from that same server, I got this error:

ERROR 2006 (HY000) at line 1721: MySQL server has gone away

When I Googled that, I saw results saying to set various options via the my.cnf file.

When I run...

updatedb && locate my.cnf

...I only see four results which are all links back to the same file: /etc/mysql/my.cnf.fallback. E.g. /etc/mysql/my.cnf.fallback == /etc/mysql/my.cnf

There are no .my.cnf files in either the root home directory or my user's home directory. I put a typo into the my.cnf file and reloaded mysql just to see the expected error and know the file was being loaded. I then removed the erroneous code and added the following:

[mysqld]
max_allowed_packet=1073741824

I then reloaded mysql by running in various ways:

service mysql restart

or

service mysql stop
service mysql start

or

/etc/init.d/mysql stop
/etc/init.d/mysql start

I then kept getting this default value indicating that it was not getting set from my.cnf:

mysql> SHOW VARIABLES LIKE 'max_allowed_packet';
+--------------------+---------+
| Variable_name      | Value   |
+--------------------+---------+
| max_allowed_packet | 4194304 |
+--------------------+---------+

If I do this:

mysql> SET GLOBAL max_allowed_packet=1073741824;

and log out and back into the mysql client, I see the correct value:

mysql> SHOW VARIABLES LIKE 'max_allowed_packet';
+--------------------+------------+
| Variable_name      | Value      |
+--------------------+------------+
| max_allowed_packet | 1073741824 |
+--------------------+------------+

But of course, if I restart the mysql server, the value reverts.

I've exhausted my search ability. What can I possibly be doing wrong?

Ron Collins
  • 93
  • 1
  • 1
  • 7

2 Answers2

12

The config files are fine. The root cause is a bug in the MySQL 5.6 packaging for Ubuntu 16.04.

If you check your /var/log/syslog you'll probably see a line like this:

Sep 15 18:56:09 ip-172-31-18-162 kernel: [  383.840275] audit: type=1400 audit(1505501769.234:50): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/etc/mysql/my.cnf.fallback" pid=25701 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

A security tool called AppArmor is denying access to a symlinked file (/etc/mysql/my.cnf.fallback).

Try this workaround, which will allow symlinks to be read by mysqld.

echo '/etc/mysql/** lr,' >> /etc/apparmor.d/local/usr.sbin.mysqld
systemctl reload apparmor

Now mysqld should see your custom config.

This bug appears to be fixed in the MySQL 5.7 Ubuntu package.

Keeth
  • 2,100
  • 2
  • 21
  • 29
  • 2
    Wow, this problem has been wrecking me and this finally did the trick. Thanks so much!!! – Christopher Kuttruff Feb 28 '18 at 18:48
  • This didn't work for me. Still can't change my config values for this version of mysql and ubuntu. spooky – mooreds Jun 20 '18 at 20:34
  • at the end of the /etc/apparmor.d/usr.sbin.mysqld I can see comment : #include so if not work, try to uncomment this line,or modify /etc/apparmor.d/usr.sbin.mysqld directly @mooreds – tinyhare Jun 29 '19 at 01:56
11

Obviously my.cnf.fallback is not the correct configuration file.

If you try this commands you can get output for possible my.cnf locations:

$ which mysqld
/usr/sbin/mysqld

$ /usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"
Default options are read from the following files in the given order:
/etc/mysql/my.cnf ~/.my.cnf /usr/etc/my.cnf

It means mysql will check those locations for my.cnf file. Simply rename /etc/mysql/my.cnf.fallback as /etc/mysql/my.cnf:

mv /etc/mysql/my.cnf.fallback /etc/mysql/my.cnf
mirza
  • 5,685
  • 10
  • 43
  • 73
  • 1
    I did as you suggested and it worked. Thanks. I am still confused because /etc/mysql/my.cnf was just a link to /etc/alternatives/my.cnf which was in tern a link to /etc/mysql/my.cnf.fallback so I figured it would read it and also as I mentioned, if I put a random string into the fallback file, mysql complained on restart but I guess mysql just couldn't follow the multiple links? Strange. Thanks again! – Ron Collins Jul 10 '16 at 20:35