Mysql – Is it possible to log MySQL variable changes

MySQLmysql-5.7percona-server

I'm using Percona MySQL server 5.7 and after a while my max_allowed_packet change to 1024 bytes and I don't know who or what application changes it.

I've set it in config file and after restart it sets fine:
[mysqld]
max_allowed_packet=100M

But after a while (few days later), my application throws error while inserting long text, it changed to 1024 bytes. I check it with:
SHOW variable LIKE 'max_allowed_packet'

Is it possible to log only variable changes to know who changed it when?

Best Answer

You can log changes that are made on-the-fly using the audit plugin. You can get that from here https://www.percona.com/doc/percona-server/LATEST/management/audit_log_plugin.html - variable changes are logged as SET commands.

The max_allowed_packet variable is set on both the client and the server - so in the [client] section and the [mysqld] section of the ini files (my.cnf for linux or my.ini for windows).

The variable may also be getting set in your application API, so you would need to check and change that too.

Finally there is an observation in the book High Performance MySQL that max_allowed_packet also controls the maximum size of a user-defined variable. These can be truncated or set to NULL if that max value is exceeded.