[Debian] MySQL Optimization, Query Monitoring, and Tuning

Created: August 27, 2018 13:25 -
Last Updated: August 29, 2018 14:24

MySQL Optimizations Query Monitoring and Tuning

MySQL drives most dynamic web content in the modern age of websites WordPress, Joomla, Drupal and most other application utilize the robust features of MySQL. Your VPS will generally come with a 'vanilla' or default install of MySQL and each site and VPS server should tune or optimize the MySQL server to their needs.

Their are many tools available either through scripts or your package manager (yum or apt) that provide MySQL information we will look at a few.

mytop

mytop is mimics the native top application in Linux but is designed for MySQL information open it gives various status pages and updates every few seconds to install the application run your package installer from SSH

Sample output:

MySQL on localhost (5.1.66-0+squeeze1) up 27+06:02:27 [19:27:23]

Queries: 3.0 qps: 0 Slow: 0.0 Se/In/Up/De(%): 5133/00/00/00

Key Efficiency: 100.0% Bps in/out: 0.0/ 0.0

Id User Host/IP DB Time Cmd Query or State

-- ---- ------- -- ---- --- --------------

292 root localhost 0 Query show full processlist

The tool will show slow queries, how many quires in real time.

MySQL Tuner

This is a script that was developed in Perl which outputs MySQL configuration information and recommends actions for performance and stability. the script can be located here MySQL Tuner

Finally we have MySQL Tuning Primer Script this script takes 'Show status like' and 'Show variable like' and then attempts to provide recommendations to your MySQL Configuration. the script can be downloaded hereMySQL Tuning Primer Script to run this tool you would also need bc installed through your package manager eg apt-get install bc

Sample output

./primer.sh all

-- MYSQL PERFORMANCE TUNING PRIMER --

- By: Matthew Montgomery -

MySQL Version 5.1.66-0+squeeze1 x86_64

Uptime = 27 days 6 hrs 24 min 46 sec

Avg. qps = 0

Total Questions = 3008

Threads Connected = 1

Server has been running for over 48hrs.

It should be safe to follow these recommendations

To find out more information on how each of these

runtime variables effects performance visit:

http://dev.mysql.com/doc/refman/5.1/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 NOT enabled.

Current long_query_time = 10.000000 sec.

You have 0 out of 3029 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 NOT enabled.

You will not be able to do point in time recovery

See http://dev.mysql.com/doc/refman/5.1/en/point-in-time-recovery.html

WORKER THREADS

Current thread_cache_size = 8

Current threads_cached = 0

Current threads_per_sec = 0

Historic threads_per_sec = 0

Your thread_cache_size is fine

MAX CONNECTIONS

Current max_connections = 151

Current threads_connected = 1

Historic max_used_connections = 1

The number of used connections is 0% 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 = 1 M

Current InnoDB data space = 1 M

Current InnoDB buffer pool free = 64 %

Current innodb_buffer_pool_size = 8 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 : 44 M

Configured Max Per-thread Buffers : 405 M

Configured Max Global Buffers : 42 M

Configured Max Memory Limit : 447 M

Physical Memory : 3.00 G

Max memory limit seem to be within acceptable norms

KEY BUFFER

Current MyISAM index space = 108 M

Current key_buffer_size = 16 M

Key cache miss rate is 1 : 1053872

Key buffer free ratio = 81 %

Your key_buffer_size seems to be too high.

Perhaps you can use these resources elsewhere

QUERY CACHE

Query cache is enabled

Current query_cache_size = 16 M

Current query_cache_used = 69 K

Current query_cache_limit = 1 M

Current Query cache Memory fill ratio = .42 %

Current query_cache_min_res_unit = 4 K

Your query_cache_size seems to be too high.

Perhaps you can use these resources elsewhere

MySQL won't cache query results that are larger than query_cache_limit in size