bbbrk

Registered
Oct 11, 2013
4
0
1
cPanel Access Level
Root Administrator
Hi!

Need help with optimization with sql - my.cnf
I've got about 12 webistes which get about 100 vistor/ one day
And one webiste which get 1000 vistors/one day
Sometimes, when you type adress you should wait few second to see page. Im sure that problem is with my.cnf.

Sorry for my bad english :(

vCPU 2000 MHz x 2 vCore
2GB RAM (4GB boost)
60GB HDD
OS Debian 6

Code:
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port		= 3306
socket		= /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket		= /var/run/mysqld/mysqld.sock
nice		= 0

innodb_buffer_pool_size=2M
innodb_additional_mem_pool_size=500K
innodb_log_buffer_size=500K
innodb_thread_concurrency=2
[mysqld]
local-infile=0
#
# * Basic Settings
#
user		= mysql
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
port		= 3306
basedir		= /usr
datadir		= /var/lib/mysql
tmpdir		= /tmp
language	= /usr/share/mysql/english
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address		= 127.0.0.1
#
# * Fine Tuning
#
key_buffer		= 16M
max_allowed_packet	= 16M
thread_stack		= 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
max_connections = 150
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit	= 1M
query_cache_size = 32M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# Here you can see queries with especially long duration
#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.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#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!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem



innodb_buffer_pool_size=2M
innodb_additional_mem_pool_size=500K
innodb_log_buffer_size=500K
innodb_thread_concurrency=2
[mysqldump]
quick
quote-names
max_allowed_packet	= 16M

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

[isamchk]
key_buffer		= 16M

#
# * 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/
 

bbbrk

Registered
Oct 11, 2013
4
0
1
cPanel Access Level
Root Administrator
before i install mysqltuner tool, i make some changes in my.cnf
acutall is
Code:
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# [url=http://dev.mysql.com/doc/mysql/en/server-system-variables.html]MySQL :: MySQL 5.6 Reference Manual :: 5.1.4 Server System Variables[/url]

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port		= 3306
socket		= /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket		= /var/run/mysqld/mysqld.sock
nice		= 0

innodb_buffer_pool_size=1536M
innodb_additional_mem_pool_size=16M
innodb_log_buffer_size=2M
innodb_thread_concurrency=2
[mysqld]
local-infile=0
#
# * Basic Settings
#
user		= mysql
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
port		= 3306
basedir		= /usr
datadir		= /var/lib/mysql
tmpdir		= /tmp
language	= /usr/share/mysql/english
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address		= 127.0.0.1
#
# * Fine Tuning
#
key_buffer		= 512M
max_allowed_packet	= 16M
thread_stack		= 192K
thread_cache_size       = 64
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
max_connections = 150
table_cache            = 1000
thread_concurrency     = 8
#
# * Query Cache Configuration
#
query_cache_limit	= 16M
query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# Here you can see queries with especially long duration
#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.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#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!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem



innodb_buffer_pool_size=1536M
innodb_additional_mem_pool_size=16M
innodb_log_buffer_size=2M
innodb_thread_concurrency=2
[mysqldump]
quick
quote-names
max_allowed_packet	= 16M

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

[isamchk]
key_buffer		= 512M

#
# * 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/
and mysqltuner:
Code:
-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.66-0+squeeze1
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster 
[--] Data in MyISAM tables: 246M (Tables: 264)
[--] Data in InnoDB tables: 156M (Tables: 349)
[!!] Total fragmented tables: 367

-------- Performance Metrics -------------------------------------------------
[--] Up for: 18h 24m 3s (1M q [15.934 qps], 10K conn, TX: 5B, RX: 154M)
[--] Reads / Writes: 87% / 13%
[--] Total buffers: 2.0G global + 2.7M per thread (150 max threads)
[OK] Maximum possible memory usage: 2.4G (61% of installed RAM)
[OK] Slow queries: 0% (0/1M)
[OK] Highest usage of available connections: 8% (12/150)
[OK] Key buffer size / total MyISAM indexes: 512.0M/58.4M
[OK] Key buffer hit rate: 99.8% (10M cached / 18K reads)
[OK] Query cache efficiency: 83.8% (787K cached / 938K selects)
[!!] Query cache prunes per day: 125226
[OK] Sorts requiring temporary tables: 0% (16 temp sorts / 37K sorts)
[!!] Joins performed without indexes: 214
[!!] Temporary tables created on disk: 30% (30K on disk / 99K total)
[OK] Thread cache hit rate: 99% (12 created / 10K connections)
[OK] Table cache hit rate: 31% (906 open / 2K opened)
[OK] Open file limit used: 29% (627/2K)
[OK] Table locks acquired immediately: 99% (232K immediate / 232K locks)
[OK] InnoDB data size / buffer pool: 156.8M/1.5G

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    MySQL started within last 24 hours - recommendations may be inaccurate
    Enable the slow query log to troubleshoot bad queries
    Adjust your join queries to always utilize indexes
    When making adjustments, make tmp_table_size/max_heap_table_size equal
    Reduce your SELECT DISTINCT queries without LIMIT clauses
Variables to adjust:
    query_cache_size (> 16M)
    join_buffer_size (> 128.0K, or always use indexes with joins)
    tmp_table_size (> 16M)
    max_heap_table_size (> 16M)
Have you got some suggestions for me ;) ?
 

thinkbot

Well-Known Member
Oct 30, 2012
326
1
16
cPanel Access Level
Root Administrator
this

query_cache_limit = 16M
query_cache_size = 16M

to

query_cache_size=50M
query_cache_limit=1M

this
innodb_buffer_pool_size=1536M

to

innodb_buffer_pool_size=400M


add there too
tmp_table_size=50M
max_heap_table_size=50M
join_buffer_size=1M
read_rnd_buffer_size=2M

slow_query_log=1
slow_query_log_file=mysql-slow.log
long_query_time=0.1


and optimize slow queries
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello :)

Also, ensure you let MySQL run for at least 24 hours before you run the MySQL tuner script again. It's important to let it run 24 hours to ensure accurate results.

Thank you.
 

bbbrk

Registered
Oct 11, 2013
4
0
1
cPanel Access Level
Root Administrator
I made some changes, and i don;t restart my server for 12 days :) so i run mysqtuner

Everything is going to be good, but i think it can be more better!

My.cnf look like:
Code:
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port		= 3306
socket		= /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket		= /var/run/mysqld/mysqld.sock
nice		= 0

innodb_buffer_pool_size=1024M
innodb_additional_mem_pool_size=16M
innodb_log_buffer_size=2M
innodb_thread_concurrency=2
[mysqld]
local-infile=0
#
# * Basic Settings
#
user		= mysql
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
port		= 3306
basedir		= /usr
datadir		= /var/lib/mysql
tmpdir		= /tmp
language	= /usr/share/mysql/english
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address		= 127.0.0.1
#
# * Fine Tuning
#
key_buffer		= 512M
max_allowed_packet	= 16M
thread_stack		= 192K
thread_cache_size       = 64
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
max_connections = 100
table_cache            = 1000
thread_concurrency     = 8
#
# * Query Cache Configuration
#
query_cache_limit	= 8M
query_cache_size =256M
tmp_table_size=512M
max_heap_table_size=512M
join_buffer_size=3M
read_rnd_buffer_size=6M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# Here you can see queries with especially long duration
#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.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#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!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
innodb_buffer_pool_size=512M
innodb_additional_mem_pool_size=16M
innodb_log_buffer_size=2M
innodb_thread_concurrency=2
[mysqldump]
quick
quote-names
max_allowed_packet	= 16M

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

[isamchk]
key_buffer		= 512M
slow_query_log=1
slow_query_log_file=mysql-slow.log
long_query_time=0.1
#
# * 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/
mysqltuner says:
Code:
-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.66-0+squeeze1
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster 
[--] Data in MyISAM tables: 248M (Tables: 264)
[--] Data in InnoDB tables: 161M (Tables: 349)
[!!] Total fragmented tables: 371

-------- Performance Metrics -------------------------------------------------
[--] Up for: 11d 23h 46m 39s (16M q [16.112 qps], 155K conn, TX: 79B, RX: 2B)
[--] Reads / Writes: 84% / 16%
[--] Total buffers: 1.8G global + 11.3M per thread (100 max threads)
[OK] Maximum possible memory usage: 2.9G (71% of installed RAM)
[OK] Slow queries: 0% (13/16M)
[OK] Highest usage of available connections: 39% (39/100)
[OK] Key buffer size / total MyISAM indexes: 512.0M/56.9M
[OK] Key buffer hit rate: 99.8% (162M cached / 357K reads)
[OK] Query cache efficiency: 87.4% (13M cached / 15M selects)
[!!] Query cache prunes per day: 24392
[OK] Sorts requiring temporary tables: 0% (60 temp sorts / 543K sorts)
[OK] Temporary tables created on disk: 24% (309K on disk / 1M total)
[OK] Thread cache hit rate: 99% (39 created / 155K connections)
[OK] Table cache hit rate: 25% (934 open / 3K opened)
[OK] Open file limit used: 29% (616/2K)
[OK] Table locks acquired immediately: 99% (3M immediate / 3M locks)
[OK] InnoDB data size / buffer pool: 161.8M/512.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    Enable the slow query log to troubleshoot bad queries
    Increasing the query_cache size over 128M may reduce performance
Variables to adjust:
    query_cache_size (> 256M) [see warning above]
So what do you think? Can you have some advice for me?