Mysql – Make changes to MySQL global variables permanent across reboots

MySQL

I'm writing an application that attempts to configure several MySQL servers remotely. Part of this configuration involves setting global MySQL variables using SQL syntax like this:

SET GLOBAL VARIABLE foo=123;

This works well, but it only lasts until the server is restarted. What I would like is a way to make MySQL write these changes to an options (.ini) file, such that they are persistent across machine reboots.

I'm trying to edit the options files without actually opening them directly – I'd prefer to do everything through the MySQL connection.

Does anyone know if this can be done?

Best Answer

You just can add all the variables to /etc/mysql/conf.d/mysql.cnf file just after [mysqld].

[mysqld]
max_connections=1000
foo=bar

if you found [mysql] replace it with [mysqld]