#
# The MySQL database server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[client]
port        = {{ mysql_port }}
socket      = /var/run/mysqld/mysqld.sock

[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0
open-files-limit = 16384

[mysqld]
# * Basic Settings
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = {{ mysql_port }}
basedir     = /usr
datadir     = {{ mysql_datadir }}
tmpdir      = {{ mysql_tempdir }}
{% if  mysql_version is version('8.0', '>=') and mysql_disable_log_bin|bool %}
disable_log_bin
{% endif %}
{% if  mysql_version is version('5.7', '<') %}
# language is for pre-5.5. In 5.5 it is an alias for lc_messages_dir.
language = {{ mysql_language }}
{% else %}
lc_messages_dir = {{ mysql_language }}
{% endif %}
bind-address = {{ mysql_bind_address }}
skip-external-locking
{% if mysql_sql_mode is defined %}
sql_mode={{ mysql_sql_mode }}
{% endif %}
{% if mysql_default_authentication_plugin is defined and mysql_version is version('5.7', '>=') %}
default_authentication_plugin={{ mysql_default_authentication_plugin }}
{% endif %}

# * Fine Tuning
key_buffer_size         = {{ mysql_key_buffer }}
max_allowed_packet      = {{ mysql_max_allowed_packet }}
thread_stack            = {{ mysql_thread_stack }}
thread_cache_size       = {{ mysql_cache_size }}
{% if  mysql_version is version('5.7', '<') %}
myisam-recover          = {{ mysql_myisam_recover }}
{% else %}
myisam-recover-options  = {{ mysql_myisam_recover }}
{% endif %}
max_connections         = {{ mysql_max_connections }}
table_open_cache        = {{ mysql_table_cache }}
{% if  mysql_version is version('5.7', '<') %}
thread_concurrency      = {{ mysql_thread_concurrency }}
{% endif %}
sort_buffer_size        = {{ mysql_sort_buffer_size }}

# ** Query Cache Configuration, removed in MySQL >= 8.0
{% if mysql_version_major|int < 8 %}
query_cache_limit       = {{ mysql_query_cache_limit }}
query_cache_size        = {{ mysql_query_cache_size }}
{% endif %}

# ** Logging and Replication
log_error = /var/log/mysql/error.log
{% if mysql_version_major|int < 8 %}
log_warnings = 2
{% else %}
log_error_verbosity = 2
{% endif %}
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
#log_slow_queries   = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
#server-id      = 1
#log_bin            = /var/log/mysql/mysql-bin.log
expire_logs_days    = 10
max_binlog_size     = 100M
#binlog_do_db       = include_database_name
#binlog_ignore_db   = include_database_name

# ** InnoDB
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
innodb_flush_log_at_trx_commit = {{ mysql_innodb_flush_log_at_trx_commit }}
innodb_buffer_pool_size = {{ mysql_innodb_buffer_pool_size }}
{% if mysql_innodb_flush_method != 'fdatasync': %}
innodb_flush_method = {{ mysql_innodb_flush_method }}
{% endif %}
innodb_lock_wait_timeout = {{ mysql_innodb_lock_wait_timeout }}
innodb_log_buffer_size = {{ mysql_innodb_log_buffer_size }}
innodb_log_file_size = {{ mysql_innodb_log_file_size }}
innodb_file_per_table = {{ mysql_innodb_file_per_table }}

{% if mysql_optimizer_switch is defined %}
# Check https://bugs.mysql.com/bug.php?id=69721 for more info
optimizer_switch = {{ mysql_optimizer_switch }}
{% endif %}

# ** Security Features
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/

character_set_server = {{ mysql_character_set_server }}
collation_server = {{ mysql_collation_server }}
character-set-client-handshake = {{ mysql_character_set_client_handshake }}

[mysqldump]
quick
quote-names
max_allowed_packet  = {{ mysql_mysqldump_max_allowed_packet }}

[mysql]
#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]
key_buffer      = {{ mysql_isamchk_key_buffer }}

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
