Quantcast
Viewing all articles
Browse latest Browse all 18770

Can we improve MySQL variable handling ?

MySQL Settings (also known as Server Variables) have interesting property. When you set variable in running server this change is not persisted in any way and server will be back to old value upon restart. MySQL also does not have option to re-read config file without restarting as some other software so approach to change config file and when instruct server to re-read it also does not work. This leads to runtime settings being different from settings set in config file, and unexpected change on restart a frequent problem.

pt-config-diff is the tool which can help with this problem a lot, being able to compare settings in my.cnf to those server is currently running with. The problem however this only works well if settings are set in my.cnf as if default option was used and we change it in run time we can’t detect such change easily because MySQL Server does not seems to have an easy way to check what was the default value for given Server Variable.

The only way I’m aware about is running the server from command line with –no-defaults –verbose –help options:

pz@ubuntu:~$ /usr/sbin/mysqld --no-defaults --verbose --help
...
timed-mutexes                                     FALSE
tmp-table-size                                    16777216
tmpdir                                            /tmp
transaction-alloc-block-size                      8192
transaction-isolation                             REPEATABLE-READ
transaction-prealloc-size                         4096
updatable-views-with-limit                        YES
userstat                                          FALSE
verbose                                           TRUE
wait-timeout                                      28800

Which is however rather ugly and only works with shell access to the server which is not always the case.

Interesting enough MySQL Allows you to SET variable to default value (compile time default, not the one server was started with) yet there seems not to be a way to read it:

mysql> set global sort_buffer_size=DEFAULT;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@global.sort_buffer_size;
+---------------------------+
| @@global.sort_buffer_size |
+---------------------------+
|                   2097152 |
+---------------------------+
1 row in set (0.00 sec)

This could be used as technique to detect the value for DEFAULT variables for SESSION variables, yet for some GLOBAL variables setting them back and forth would not be safe.

The simple change which would make dealing with MySQL variables in automated way a lot more convenient would be extending INFORMATION_SCHEMA.GLOBAL_VARIABLES Currently as of MySQL 5.5 it contains only variable name and value. Yet I would suggest adding few more columns such as DEFAULT – to hold compile time default value for variable and STARTUP to hold the value the server was started with.

It also might be good idea to extend SELECT syntax to ease querying of variable global value Right now I can select:

mysql> select @@global.sort_buffer_size;
+---------------------------+
| @@global.sort_buffer_size |
+---------------------------+
|                   2097152 |
+---------------------------+
1 row in set (0.00 sec)

If I could only refer to “default” or “startup” in addition to “global” and “session” prefixes which are available now it would be quite nice.


PlanetMySQL Voting: Vote UP / Vote DOWN

Viewing all articles
Browse latest Browse all 18770

Trending Articles