Suggestions on Tuning MySQL Parameters
Parameters are key configuration items in a database system. Improper parameter settings may adversely affect the stable running of databases. This section describes some important parameters for your reference. For details, see MySQL official website.
Sensitive Parameters
Example parameters are as follows:
- lower_case_table_names
Default value: 1
Function: Controls whether database and tables stored on disks are case sensitive. If the parameter value is set to 1, database and table names are lowercase by default. If the parameter value is set to 0, names stored and name queries are case sensitive.
MySQL 8.0 does not support any modifications to this parameter.
Impact: If you change the parameter value of a primary DB instance, you should also change the parameter values for associated read replicas and DB instances restored from the backup. For example, tables abc and Abc in a primary DB instance are case sensitive, but tables in the associated read replicas and the DB instance restored from the backup are case insensitive. During data synchronization and restoration, errors may occur because the table named abc already exists.
- innodb_flush_log_at_trx_commit
Default value: 1
Function: Controls the balance between strict ACID compliance for commit operations and higher performance. The default setting of 1 is required for full ACID compliance. Logs are written and flushed to disks at each transaction commit. If the value is set to 0, logs are written and flushed to disks once per second. If the value is set to 2, logs are written at each transaction commit and flushed to disks every two seconds.
Impact: If this parameter is not set to 1, data security is not guaranteed. When the system fails, data may be lost.
- sync_binlog
Default value: 1
Function: Controls how often the MySQL server synchronizes binary logs to the disk. The default setting of 1 requires synchronization of the binary log to the disk at each transaction commit. If the value is set to 0, synchronization of the binary log to the disk is not controlled by the MySQL server but relies on the OS to flush the binary log to the disk. This setting provides the best performance, but in the event of a power failure or OS crash, all binary log information in binlog_cache is lost.
Impact: If this parameter is not set to 1, data security is not guaranteed. When the system fails, data may be lost.
Performance Parameters
Relevant parameters are as follows:
- The values of innodb_spin_wait_delay and query_alloc_block_size are determined by the DB instance specifications. If you increase their values, database performance may be affected.
- If key_buffer_size is set to a value smaller than 4096, the parameter modification will fail.
- If max_connections is set to a small value, database access will be affected.
- The default values of the following parameters are determined by the DB instance specifications: innodb_buffer_pool_size, max_connections, and back_log. These parameter values are default before being specified.
- The values of innodb_io_capacity_max and innodb_io_capacity are determined by the storage type. These parameter values are default before being specified.
Associated Parameters
- character_set_server: If you change the value of this parameter, the system changes the values of collation_server, character_set_database, and collation_database accordingly.
The parameters character_set_server and collation_server are correlated with each other. For example, for MySQL 5.7, when character_set_server is latin1, the default value of collation_server is latin1_swedish_ci. The collation_server value must start with latin1.
- innodb_io_capacity: The value of this parameter must be less than or equal to the value of innodb_io_capacity_max. For example, if innodb_io_capacity_max is set to 2000, the maximum value of innodb_io_capacity is 2000.
- innodb_buffer_pool_size: The value of this parameter must be an integral multiple of the product of innodb_buffer_pool_chunk_size and innodb_buffer_pool_instances. For example, if innodb_buffer_pool_chunk_size is 134217728 and innodb_buffer_pool_instances is 1, the value of innodb_buffer_pool_size must be an integral multiple to 134217728.
Other Parameters
- max_prepared_stmt_count: Preparing a large number of statements consumes server memory resources. If this parameter is set to a small value, the denial of service (DoS) risk may occur. You are advised to change the parameter value based on service requirements.
- The values of the following parameters will be adjusted based on kernel rules as follows:
- key_cache_age_threshold: automatically adjusted to a multiple of 100.
- join_buffer_size and key_cache_block_size: automatically adjusted to multiples of 128.
- query_cache_size, query_prealloc_size, innodb_log_buffer_size, max_allowed_packet, and thread_stack: automatically adjusted to multiples of 1024.
- read_buffer_size, read_rnd_buffer_size, binlog_cache_size, and binlog_stmt_cache_size: automatically adjusted to multiples of 4096.
- data_buffer_size, log_buffer_size, shared_pool_size, and temp_buffer_size: automatically adjusted to multiples of 1048576.
- binlog_format: set to row by default, indicating that binary logs are recorded as the modified data by row, including the data before and after modification. You are advised not to change the value of this parameter.
- log_timestamps: controls the time zone of timestamps in messages written to the error log, and in general query log and slow query log messages written to files. The default value is the system time zone and cannot be changed.
Last Article: Parameter Template Management
Next Article: Creating a Parameter Template
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.