MySQL my.cnf configuration for dedicated server?

DaRecordon

Well-known member
Joined
Oct 7, 2016
Messages
201
Points
18
I have a dedicated server and running mysql on it, I heard that i shuold optimize my.cnf configuration for my dedicated server to get best performance for mysql, but what are configuration to put into my.cnf to obtain that? Can anyone suggest me?
 

AlbaHost

Well-known member
Joined
Jan 18, 2017
Messages
463
Points
43
I have a dedicated server and running mysql on it, I heard that i shuold optimize my.cnf configuration for my dedicated server to get best performance for mysql, but what are configuration to put into my.cnf to obtain that? Can anyone suggest me?
What is your current config file? You may first run mysqltuner script and find out more information. Also you did not even provide your dedicated server configuration too.
 

DaRecordon

Well-known member
Joined
Oct 7, 2016
Messages
201
Points
18

AlbaHost

Well-known member
Joined
Jan 18, 2017
Messages
463
Points
43
AlbaHost
Because mysql configuration is based on server configuration to prevent server performance degration as @JoivHost stated. Post your my.cnf to see your current configuration, as you have 32GB of ram you may try this config:
Code:
[mysql]
port                            = 3306
socket                          = /var/run/mysqld/mysqld.sock

[mysqld]
# Required Settings
basedir                         = /usr
bind_address                    = 127.0.0.1 # Change to 0.0.0.0 to allow remote connections
datadir                         = /var/lib/mysql
max_allowed_packet              = 256M
max_connect_errors              = 1000000
pid_file                        = /var/run/mysqld/mysqld.pid
port                            = 3306
skip_external_locking
skip_name_resolve
socket                          = /var/run/mysqld/mysqld.sock

# Enable for b/c with databases created in older MySQL/MariaDB versions (e.g. when using null dates)
#sql_mode                       = ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES

tmpdir                          = /tmp
user                            = mysql

# InnoDB Settings
default_storage_engine          = InnoDB
innodb_buffer_pool_instances    = 8     # Use 1 instance per 1GB of InnoDB pool size
innodb_buffer_pool_size         = 8G    # Use up to 70-80% of RAM
innodb_file_per_table           = 1
innodb_flush_log_at_trx_commit  = 0
innodb_flush_method             = O_DIRECT
innodb_log_buffer_size          = 16M
innodb_log_file_size            = 512M
innodb_stats_on_metadata        = 0

#innodb_temp_data_file_path     = ibtmp1:64M:autoextend:max:20G # Control the maximum size for the ibtmp1 file
#innodb_thread_concurrency      = 4     # Optional: Set to the number of CPUs on your system (minus 1 or 2) to better
                                        # contain CPU usage. E.g. if your system has 8 CPUs, try 6 or 7 and check
                                        # the overall load produced by MySQL/MariaDB.
innodb_read_io_threads          = 64
innodb_write_io_threads         = 64

# MyISAM Settings
query_cache_limit               = 4M    # UPD - Option supported by MariaDB & up to MySQL 5.7, remove this line on MySQL 8.x
query_cache_size                = 64M   # UPD - Option supported by MariaDB & up to MySQL 5.7, remove this line on MySQL 8.x
query_cache_type                = 1     # Option supported by MariaDB & up to MySQL 5.7, remove this line on MySQL 8.x

key_buffer_size                 = 32M   # UPD

low_priority_updates            = 1
concurrent_insert               = 2

# Connection Settings
max_connections                 = 100   # UPD

back_log                        = 512
thread_cache_size               = 100
thread_stack                    = 192K

interactive_timeout             = 180
wait_timeout                    = 180

# For MySQL 5.7+ only (disabled by default)
#max_execution_time             = 30000 # Set a timeout limit for SELECT statements (value in milliseconds).
                                        # This option may be useful to address aggressive crawling on large sites,
                                        # but it can also cause issues (e.g. with backups). So use with extreme caution and test!
                                        # More info at: https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_max_execution_time

# For MariaDB 10.1.1+ only (disabled by default)
#max_statement_time             = 30    # The equivalent of "max_execution_time" in MySQL 5.7+ (set above)
                                        # The variable is of type double, thus you can use subsecond timeout.
                                        # For example you can use value 0.01 for 10 milliseconds timeout.
                                        # More info at: https://mariadb.com/kb/en/aborting-statements/

# Buffer Settings
join_buffer_size                = 4M    # UPD
read_buffer_size                = 3M    # UPD
read_rnd_buffer_size            = 4M    # UPD
sort_buffer_size                = 4M    # UPD

# Table Settings
# In systemd managed systems like Ubuntu 16.04+ or CentOS 7+, you need to perform an extra action for table_open_cache & open_files_limit
# to be overriden (also see comment next to open_files_limit).
# E.g. for MySQL 5.7, please check: https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html
# and for MariaDB check: https://mariadb.com/kb/en/library/systemd/
table_definition_cache          = 40000 # UPD
table_open_cache                = 40000 # UPD
open_files_limit                = 60000 # UPD - This can be 2x to 3x the table_open_cache value or match the system's
                                        # open files limit usually set in /etc/sysctl.conf or /etc/security/limits.conf
                                        # In systemd managed systems this limit must also be set in:
                                        # /etc/systemd/system/mysqld.service.d/override.conf (for MySQL 5.7+) and
                                        # /etc/systemd/system/mariadb.service.d/override.conf (for MariaDB)

max_heap_table_size             = 128M
tmp_table_size                  = 128M

# Search Settings
ft_min_word_len                 = 3     # Minimum length of words to be indexed for search results

# Logging
log_error                       = /var/lib/mysql/mysql_error.log
log_queries_not_using_indexes   = 1
long_query_time                 = 5
slow_query_log                  = 0     # Disabled for production
slow_query_log_file             = /var/lib/mysql/mysql_slow.log

[mysqldump]
# Variable reference
# For MySQL 5.7: https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html
# For MariaDB:   https://mariadb.com/kb/en/library/mysqldump/
quick
quote_names
max_allowed_packet              = 64M
 
Last edited:

AlbaHost

Well-known member
Joined
Jan 18, 2017
Messages
463
Points
43
AlbaHost
Make backup of your current configuration before you apply new config, so that if anything would go wrong you can restore it.
 

JoivHost

Corporate Member
Corporate Member
Joined
Jul 5, 2020
Messages
13
Points
1
You can install and run MySQLTuner with those cmd's:
Code:
wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl
chmod +x mysqltuner.pl
./mysqltuner.pl
It will give you information about your current MySQL performance + suggestions.

MySQL must be optimized according to the specifications of your server.
Otherwise, it may degrade the server performance.
 

DaRecordon

Well-known member
Joined
Oct 7, 2016
Messages
201
Points
18
DaRecordon
MySQL must be optimized according to the specifications of your server.
Sure I must try your commands to see which mysql configs should work with my server. Honestly I have a server 32 GB RAM but I think I still need to optimize Mysql to have better performance.
 

JoivHost

Corporate Member
Corporate Member
Joined
Jul 5, 2020
Messages
13
Points
1
JoivHost
You can also post your my.cnf here, to have some starting point. Disk type will be useful too.
 

DaRecordon

Well-known member
Joined
Oct 7, 2016
Messages
201
Points
18
DaRecordon
When I run this command, it gave the result like this

Code:
[[email protected] ~]# ./mysqltuner.pl
>>  MySQLTuner 1.7.19 - Major Hayden <[EMAIL][email protected][/EMAIL]>
>>  Bug reports, feature requests, and downloads at [URL]http://mysqltuner.com/[/URL]
>>  Run with '--help' for additional options and output filtering

[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.7.27
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ----------------------------------------------                                                                                                       --------------------
[OK] Log file /var/log/mysql.log exists
[--] Log file: /var/log/mysql.log(0B)
[OK] Log file /var/log/mysql.log is readable.
[!!] Log file /var/log/mysql.log is empty
[OK] Log file /var/log/mysql.log is smaller than 32 Mb
[OK] /var/log/mysql.log doesn't contain any warning.
[OK] /var/log/mysql.log doesn't contain any error.
[--] 0 start(s) detected in /var/log/mysql.log
[--] 0 shutdown(s) detected in /var/log/mysql.log

-------- Storage Engine Statistics ---------------------------------------------                                                                                                       --------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +My                                                                                                       ISAM +PERFORMANCE_SCHEMA
[--] Data in MyISAM tables: 308.7M (Tables: 98)
[--] Data in InnoDB tables: 1.3G (Tables: 974)
[--] Data in MEMORY tables: 4.6M (Tables: 13)
[OK] Total fragmented tables: 0

-------- Analysis Performance Metrics ------------------------------------------                                                                                                       --------------------
[--] innodb_stats_on_metadata: OFF
[OK] No stat updates during querying INFORMATION_SCHEMA.

-------- Security Recommendations ----------------------------------------------                                                                                                       --------------------
[OK] There are no anonymous accounts for any database users
[OK] All database users have passwords assigned
[!!] There is no basic password file list!

-------- CVE Security Recommendations ------------------------------------------                                                                                                       --------------------
[--] Skipped due to --cvefile option undefined

-------- Performance Metrics ---------------------------------------------------                                                                                                       --------------------
[--] Up for: 55d 0h 46m 7s (359M q [75.576 qps], 10M conn, TX: 4225G, RX: 94G)
[--] Reads / Writes: 96% / 4%
[--] Binary logging is disabled
[--] Physical Memory     : 31.1G
[--] Max MySQL memory    : 942.9M
[--] Other process memory: 0B
[--] Total buffers: 169.0M global + 5.1M per thread (151 max threads)
[--] P_S Max memory usage: 72B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 948.0M (2.97% of installed RAM)
[OK] Maximum possible memory usage: 942.9M (2.96% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory                                                                                                        available
[OK] Slow queries: 0% (0/359M)
[!!] Highest connection usage: 100%  (152/151)
[OK] Aborted connections: 0.06%  (5909/10404067)
[!!] name resolution is active : a reverse name resolution is made for each new                                                                                                        connection and can reduce performance
[!!] Query cache may be disabled by default due to mutex contention.
[!!] Query cache efficiency: 0.0% (0 cached / 310M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 1% (1M temp sorts / 103M sorts)
[!!] Joins performed without indexes: 112523
[OK] Temporary tables created on disk: 13% (7M on disk / 54M total)
[OK] Thread cache hit rate: 99% (22K created / 10M connections)
[!!] Table cache hit rate: 0% (2K open / 10M opened)
[OK] table_definition_cache(1400) is upper than number of tables(1364)
[OK] Open file limit used: 0% (354/655K)
[OK] Table locks acquired immediately: 99% (176M immediate / 176M locks)

-------- Performance schema ----------------------------------------------------                                                                                                       --------------------
[--] Memory used by P_S: 72B
[--] Sys schema is installed.

-------- ThreadPool Metrics ----------------------------------------------------                                                                                                       --------------------
[--] ThreadPool stat is disabled.

-------- MyISAM Metrics --------------------------------------------------------                                                                                                       --------------------
[!!] Key buffer used: 39.0% (3M used / 8M cache)
[OK] Key buffer size / total MyISAM indexes: 8.0M/103.0M
[OK] Read Key buffer hit rate: 99.9% (1B cached / 1M reads)
[!!] Write Key buffer hit rate: 46.4% (8M cached / 4M writes)

-------- InnoDB Metrics --------------------------------------------------------                                                                                                       --------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[!!] InnoDB buffer pool / data size: 128.0M/1.3G
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (75 %): 48.0M * 2/128.                                                                                                       0M should be equal to 25%
[OK] InnoDB buffer pool instances: 1
[--] Number of InnoDB Buffer Pool Chunk : 1 for 1 Buffer Pool Instance(s)
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb                                                                                                       _buffer_pool_instances
[OK] InnoDB Read buffer efficiency: 99.98% (188591810567 hits/ 188636399452 tota                                                                                                       l)
[!!] InnoDB Write Log efficiency: 81.52% (11238022 hits/ 13785373 total)
[OK] InnoDB log waits: 0.00% (0 waits / 2547351 writes)

-------- AriaDB Metrics --------------------------------------------------------                                                                                                       --------------------
[--] AriaDB is disabled.

-------- TokuDB Metrics --------------------------------------------------------                                                                                                       --------------------
[--] TokuDB is disabled.

-------- XtraDB Metrics --------------------------------------------------------                                                                                                       --------------------
[--] XtraDB is disabled.

-------- Galera Metrics --------------------------------------------------------                                                                                                       --------------------
[--] Galera is disabled.

-------- Replication Metrics ---------------------------------------------------                                                                                                       --------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] Binlog format: ROW
[--] XA support enabled: ON
[--] Semi synchronous replication Master: Not Activated
[--] Semi synchronous replication Slave: Not Activated
[--] This is a standalone server

-------- Recommendations -------------------------------------------------------                                                                                                       --------------------
General recommendations:
    Reduce or eliminate persistent connections to reduce connection usage
    Configure your accounts with ip or subnets only, then update your configurat                                                                                                       ion with skip-name-resolve=1
    We will suggest raising the 'join_buffer_size' until JOINs not using indexes                                                                                                        are found.
             See [URL]https://dev.mysql.com/doc/internals/en/join-buffer-size.html[/URL]
             (specially the conclusions at the bottom of the page).
    Increase table_open_cache gradually to avoid file descriptor limits
    Read this before increasing table_open_cache over 64: [URL]https://bit.ly/2Fulv7r[/URL]
    Read this before increasing for MariaDB [URL]https://mariadb.com/kb/en/library/op[/URL]                                                                                                       timizing-table_open_cache/
    This is MyISAM only table_cache scalability problem, InnoDB not affected.
    See more details here: [URL]https://bugs.mysql.com/bug.php?id=49177[/URL]
    This bug already fixed in MySQL 5.7.9 and newer MySQL versions.
    Beware that open_files_limit (655350) variable
    should be greater than table_open_cache (2000)
    Before changing innodb_log_file_size and/or innodb_log_files_in_group read t                                                                                                       his: [URL]https://bit.ly/2TcGgtU[/URL]
Variables to adjust:
    max_connections (> 151)
    wait_timeout (< 28800)
    interactive_timeout (< 28800)
    query_cache_size (=0)
    query_cache_type (=0)
    query_cache_limit (> 1M, or use smaller result sets)
    join_buffer_size (> 256.0K, or always use indexes with JOINs)
    table_open_cache (> 2000)
    innodb_buffer_pool_size (>= 1.3G) if possible.
    innodb_log_file_size should be (=16M) if possible, so InnoDB total log files                                                                                                        size equals to 25% of buffer pool size.
[[email protected] ~]#
 

JoivHost

Corporate Member
Corporate Member
Joined
Jul 5, 2020
Messages
13
Points
1
JoivHost
Yes, and you can start with the recommendations in this result.
You can try @AlbaHost configuration (as he said backup your own my.cnf before that) and continue run mysqltuner and ajust your config until your get satisfactory performance.
 

DaRecordon

Well-known member
Joined
Oct 7, 2016
Messages
201
Points
18
DaRecordon
Yes i can try the issue is, how to measure the result before and after applying new result. I want to know if the new result is better and giving better performance or not.
 
Older Threads
Replies
19
Views
425
Replies
4
Views
156
Replies
2
Views
110
Replies
2
Views
137
Latest Threads
Recommended Threads
Replies
3
Views
2,071
Replies
8
Views
1,856
Replies
7
Views
1,513
Replies
0
Views
1,666

Sponsors

Latest Blog ArticlesMost Viewed Threads

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top