Could you help me Optimize MySQL

xuancong6000

Verified User
Joined
Oct 12, 2012
Messages
79
I do this command: perl mysqltuner.pl and it show overload RAM
Code:
[root@server ~]# perl mysqltuner.pl

 >>  MySQLTuner 1.2.0 - Major Hayden <[email protected]>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering
Please enter your MySQL administrative login: root
Please enter your MySQL administrative password: 

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

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster 
[--] Data in MyISAM tables: 34M (Tables: 1451)
[--] Data in InnoDB tables: 52M (Tables: 449)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[--] Data in MEMORY tables: 2M (Tables: 23)
[!!] Total fragmented tables: 481

-------- Security Recommendations  -------------------------------------------
[OK] All database users have passwords assigned

-------- Performance Metrics -------------------------------------------------
[--] Up for: 5m 4s (1K q [5.572 qps], 68 conn, TX: 8M, RX: 217K)
[--] Reads / Writes: 77% / 23%
[--] Total buffers: 276.0M global + 40.2M per thread (100 max threads)
[!!] Maximum possible memory usage: 4.2G (210% of installed RAM)
[OK] Slow queries: 0% (0/1K)
[OK] Highest usage of available connections: 1% (1/100)
[OK] Key buffer size / total MyISAM indexes: 100.0M/9.6M
[OK] Key buffer hit rate: 97.2% (3K cached / 94 reads)
[OK] Query cache efficiency: 57.9% (760 cached / 1K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 52 sorts)
[OK] Temporary tables created on disk: 4% (1 on disk / 22 total)
[OK] Thread cache hit rate: 98% (1 created / 68 connections)
[!!] Table cache hit rate: 4% (256 open / 5K opened)
[OK] Open file limit used: 2% (198/8K)
[OK] Table locks acquired immediately: 100% (825 immediate / 825 locks)
[OK] InnoDB data size / buffer pool: 52.5M/128.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    MySQL started within last 24 hours - recommendations may be inaccurate
    Reduce your overall MySQL memory footprint for system stability
    Enable the slow query log to troubleshoot bad queries
    Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
  *** MySQL's maximum memory usage is dangerously high ***
  *** Add RAM before increasing MySQL buffer variables ***
    table_cache (> 256)

[root@server ~]#
this is my my.cnf
Code:
[client]
port		= 3306
socket		= /var/lib/mysql/mysql.sock
[mysqld]
port		= 3306
socket		= /var/lib/mysql/mysql.sock
skip-external-locking
max_connections = 100
interactive_timeout = 100
wait_timeout = 100
connect_timeout = 10
thread_cache_size = 128
key_buffer_size = 100M
join_buffer = 1M
join_buffer_size = 32M
table_open_cache = 256
sort_buffer_size = 2M
read_buffer_size = 2M
max_connect_errors=10
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 32M
query_cache_size= 16M
thread_concurrency = 8
[safe_mysqld]
err-log=/var/log/mysqld.log
open_files_limit=8192
log-bin=mysql-bin
binlog_format=mixed
server-id	= 1
[mysqldump]
quick
max_allowed_packet = 2M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 64M
sort_buffer = 64M
read_buffer = 4M
write_buffer = 4M
[myisamchk]
query_cache_limit = 2M
table_cache = 256
max_heap_table_size = 32M
tmp_table_size = 128M
[mysqlhotcopy]
interactive-timeout
it have some problem:
Code:
[!!] Total fragmented tables: 481
[!!] Maximum possible memory usage: 4.2G (210% of installed RAM)
[!!] Table cache hit rate: 4% (256 open / 5K opened)
My VPS had 2GB of RAM and 4 Core of CPU E3-1270 V2 @ 3.50GHz
could you please help me Optimize MySQL
thanks alot
 
Hello,

You'd better start from default configs which go with every MySQL installations:

my-huge.cnf.
my-innodb-heavy-4G.cnf
my-large.cnf
my-medium.cnf
my-small.cnf

Or hire somebody to do he job for you. It's not the right place to configure your MySQL on this forums.
Useful reading: http://www.mysqlperformanceblog.com...for-generating-optimal-mycnf-files-for-mysql/

Yes thanks I used my-huge.cnf and edit something can you see and for me opinion about this:

first thí is my my.cnf
Code:
# Example MySQL config file for very large systems.
#
# This is for a large system with memory of 1G-2G where the system runs mainly
# MySQL.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password	= your_password
port		= 3306
socket		= /var/lib/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port		= 3306
socket		= /var/lib/mysql/mysql.sock
max_connections = 100
table_cache= 256 
skip-external-locking
key_buffer_size = 256M
join_buffer_size = 1M
max_allowed_packet = 1M
table_open_cache = 10000
table_definition_cache = 10000
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 3M
query_cache_limit = 512K
expire_logs_days = 7
log-slow-queries=/var/lib/mysql/slow.log
log-queries-not-using-indexes
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 4

#Additional configuration:
wait_timeout=15 #The number of seconds the server waits for activity on a noninteractive connection before closing it.
connect_timeout=30 #The number of seconds that the mysqld server waits for a connect packet before responding with Bad, default is 10 second
max_user_connections = 100
max_connect_errors = 100
low_priority_updates=1

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
# 
#skip-networking

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id	= 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =   <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
#
# binary logging format - mixed recommended 
#binlog_format=mixed

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /var/lib/mysql
#innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 384M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 100M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

this is check of perl mysqltuner.pl:
Code:
[root@server ~]# perl mysqltuner.pl

 >>  MySQLTuner 1.2.0 - Major Hayden <[email protected]>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering
Please enter your MySQL administrative login: root
Please enter your MySQL administrative password:

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.5.29-log
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 291M (Tables: 2350)
[--] Data in InnoDB tables: 35M (Tables: 314)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[--] Data in MEMORY tables: 2M (Tables: 35)
[!!] Total fragmented tables: 344

-------- Security Recommendations  -------------------------------------------
[OK] All database users have passwords assigned

-------- Performance Metrics -------------------------------------------------
[--] Up for: 2m 2s (6K q [54.082 qps], 221 conn, TX: 98M, RX: 1M)
[--] Reads / Writes: 81% / 19%
[--] Total buffers: 419.0M global + 13.2M per thread (100 max threads)
[OK] Maximum possible memory usage: 1.7G (85% of installed RAM)
[OK] Slow queries: 1% (128/6K)
[OK] Highest usage of available connections: 2% (2/100)
[OK] Key buffer size / total MyISAM indexes: 256.0M/46.2M
[OK] Key buffer hit rate: 97.3% (33K cached / 904 reads)
[OK] Query cache efficiency: 82.7% (4K cached / 5K selects)
[!!] Query cache prunes per day: 43200
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 281 sorts)
[OK] Temporary tables created on disk: 12% (43 on disk / 341 total)
[OK] Thread cache hit rate: 99% (2 created / 221 connections)
[OK] Table cache hit rate: 49% (2K open / 5K opened)
[OK] Open file limit used: 23% (4K/20K)
[OK] Table locks acquired immediately: 100% (2K immediate / 2K locks)
[OK] InnoDB data size / buffer pool: 35.1M/128.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    MySQL started within last 24 hours - recommendations may be inaccurate
Variables to adjust:
    query_cache_size (> 3M)

[root@server ~]#

and the last is tuning-primer.sh

Code:
[root@server ~]# sh tuning-primer.sh

Using login values from ~/.my.cnf
- INITIAL LOGIN ATTEMPT FAILED -
Testing for stored webmin passwords:
 None Found
Could not auto detect login info!
Found potential sockets: /var/lib/mysql/mysql.sock
Using: /var/lib/mysql/mysql.sock
Would you like to provide a different socket?: [y/N] n
Do you have your login handy ? [y/N] : y
User:
Password:

Would you like me to create a ~/.my.cnf file for you? [y/N] : n

        -- MYSQL PERFORMANCE TUNING PRIMER --
             - By: Matthew Montgomery -

MySQL Version 5.5.29-log x86_64

Uptime = 0 days 0 hrs 0 min 54 sec
Avg. qps = 49
Total Questions = 2650
Threads Connected = 1

Warning: Server has not been running for at least 48hrs.
It may not be safe to use these recommendations

To find out more information on how each of these
runtime variables effects performance visit:
http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html
Visit http://www.mysql.com/products/enterprise/advisors.html
for info about MySQL's Enterprise Monitoring and Advisory Service

SLOW QUERIES
The slow query log is enabled.
Current long_query_time = 10.000000 sec.
You have 54 out of 2671 that take longer than 10.000000 sec. to complete
Your long_query_time seems to be fine

BINARY UPDATE LOG
The binary update log is enabled
Binlog sync is not enabled, you could loose binlog records during a server crash

WORKER THREADS
Current thread_cache_size = 8
Current threads_cached = 1
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 100
Current threads_connected = 1
Historic max_used_connections = 2
The number of used connections is 2% of the configured maximum.
You are using less than 10% of your configured max_connections.
Lowering max_connections could help to avoid an over-allocation of memory
See "MEMORY USAGE" section to make sure you are not over-allocating

INNODB STATUS
Current InnoDB index space = 19 M
Current InnoDB data space = 35 M
Current InnoDB buffer pool free = 73 %
Current innodb_buffer_pool_size = 128 M
Depending on how much space your innodb indexes take up it may be safe
to increase this value to up to 2 / 3 of total system memory

MEMORY USAGE
Max Memory Ever Allocated : 429 M
Configured Max Per-thread Buffers : 1.29 G
Configured Max Global Buffers : 403 M
Configured Max Memory Limit : 1.69 G
Physical Memory : 2.00 G
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 46 M
Current key_buffer_size = 256 M
Key cache miss rate is 1 : 33
Key buffer free ratio = 81 %
Your key_buffer_size seems to be fine

QUERY CACHE
Query cache is enabled
Current query_cache_size = 3 M
Current query_cache_used = 2 M
Current query_cache_limit = 512 K
Current Query cache Memory fill ratio = 84.15 %
Current query_cache_min_res_unit = 4 K
MySQL won't cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 2 M
Current read_rnd_buffer_size = 6 M
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 3.00 M
You have had 0 queries where a join could not use an index properly
Your joins seem to be using indexes properly

OPEN FILES LIMIT
Current open_files_limit = 20110 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
Your open_files_limit value seems to be fine

TABLE CACHE
Current table_open_cache = 10000 tables
Current table_definition_cache = 10000 tables
You have a total of 2740 tables
You have 2741 open tables.
The table_cache value seems to be fine

TEMP TABLES
Current max_heap_table_size = 16 M
Current tmp_table_size = 16 M
Of 283 temp tables, 13% were created on disk
Created disk tmp tables ratio seems fine

TABLE SCANS
Current read_buffer_size = 2 M
Current table scan ratio = 192 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 0 : 2991
Your table locking seems to be fine

[root@server ~]#

This is the first I do that thanks
 
Last edited:
Back
Top