MySQL: Global Variables and Configuration
by Mark Nielsen
Copyright 2022
In time, we will adding more sections.
- Links
- Linux system configuration
- MySQL, Percona, MariaDB
- Galera
Links
- https://mariadb.com/kb/en/server-system-variables/
- https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html
- https://mariadb.com/kb/en/galera-cluster-system-variables/https://mariadb.com/kb/en/galera-cluster-system-variables/
- https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Reference.html
- https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Reference.html#AuroraMySQL.Reference.ParameterGroups
https://www.percona.com/blog/2018/07/03/linux-os-tuning-for-mysql-database-performance/
- https://www.psce.com/en/blog/2012/04/12/how-to-install-and-configure-a-linux-server-for-mysql/
- https://www.samsung.com/semiconductor/global.semi.static/best-practices-for-mysql-with-ssds-0.pdf
- https://www.virtual-dba.com/blog/linux-os-and-file-system-tuning-for-database-servers/
- https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/storage_administration_guide/xfsmounting
- https://dev.mysql.com/doc/refman/8.0/en/innodb-multiple-buffer-pools.html
- Use a diagnosis tool
https://www.pcwdld.com/mysql-monitoring-tools
- https://seo-explorer.io/blog/five-ways-to-improve-mysql-select-speed-part-1/
- https://www.percona.com/blog/2014/01/28/10-mysql-performance-tuning-settings-after-installation/
- https://severalnines.com/database-blog/mysql-performance-cheat-sheet
- https://orangematter.solarwinds.com/2017/01/13/solving-mysql-replication-lag-with-logical_clock-and-calibrated-delay/
- https://dev.mysql.com/doc/refman/5.6/en/optimizing-innodb-diskio.html
Linux
MySQL, Percona, MariaDB
We will include INNODB settings in the lists below. We manually add sections
for other engines later.
Very important configurations
- Not really a configuration, but run "explain" on queries and analyze your slow
log. Queries might not use indexes right, might have temporary tables that right to
disk, buffers (join, read, write, sort, etc)
might be big enough, there might be an "or" condition in a join, or
many others reasons why it is not efficient.
- Make sure you innodb buffer pool uses 75% of ram.
- Make sure you have big innodb logs. If they are small and fill up queries
go slow. Some people like small logs so failovers happen quick. But if the logs
are big enough a failover might not have to happen. There is no logical reason why
to have small innodb logs if you have good failover technology. You might want to
GTID, automatic failovers, and semisynchronous replication.
- sync
- You should have multiple buffer pools for innodb. "1" per gig is good.
- Make one file per table for innodb is turned on.
- Make sure your table cache is big enough for all tables and table partitions.
- Make sure the amount of memory to innodb buffer pool covers all hot data if your
data is bigger than the amount of ram.
- Use a diagnosis tool like Solar Winds. Not a configuration change but can lead
to configuration changes.
- You might want to configure indirect things like slow logs and
Performance Schema correctly.
- skip_name_resolve makes it faster.
- Some other variables: thread_cache_size, max_connections, turn off query cache,
thread_pool_size, temp tables (tmp_table_size, max_heap_table_size),
table_open_cache, table_open_cache, table_definition_cache,
max_allowed_packet (if you have big data), innodb_flush_method,
innodb_adaptive_flushing, slave_compressed_protocol( might help),
- Use multi-threaded replication and maybe slave_parallel_type = LOGICAL_CLOCK;
- Increasing threads for read, write, purge, concurrency.
- Set innodb_log_buffer_size to 64M, innodb_log_file_size to 1G or higher is
you have SSD drives.
Temporary Speed Boost
There are times when you need a speed boost. This can be the master or on a Slave.
If this becomes a regular habit, consider setting the server for upgrading,
horizontal scaling, or vertical scaling, a cache like Redis, load balancing,
sharding, etc. I might add more variables here in the future.
- innodb_flush_log_at_trx_commit=1 is very normal for use.
If you want to speed it up
temporarily you can set it to 2, which is mostly safe.
"0" is even faster, but dangerous. I wouldn't do "0" on a Master.
- sync_binlog is normally 1, set it to 0 to speed a Slave up temporarily.
Setting higher than 1 make it faster, maybe, and it will effect
binlog_group_commit_sync_delay.
- Run pt-stalk when problems occur. It may help. Not really a speed
boot now, but it may help for the future. Solar Winds and other monitoring
systems can also provide information on this.
Galera
I don't have much to say on Galera right now. I only have had a few instances
where I had to figure out issues.
- Try to write all writes to one node.
- Try to do single row inserts, deletes, and selects.
- Use a Slave off of one of the nodes for time insensitive selects.
- A 4th node might be good for backups.
- Load balance the selects. Might not want to default to the write node.
- Increase the amount of timeouts might help to prevent a node from being
kicked out.
- gcache.size=1G or more to allow downtime and then to reconnect.
- You might also want to check out: Parallel Slave Threads,
- You might want to relax syncs or trx commit values if you can rely on one node
being out (innodb_flush_log_at_trx_commit = 1).
- You might want a 4th node, it doesn't add HA availability, but it might
be useful to add the 4th node into the load balance and
remove another node for upgrades, to get it becoome stable, or to fix the node.
You might want
to permanently leave out the 4th node, which could be used for backups
most of the time.