MySQL Performance Tuning

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

MySQL Performance Tuning

Version 1
Folder structure in Ubuntu 20.04

/etc/mysql

conf.d my.cnf my.cnf.fallback mysql.cnf mysql.conf.d

mysql.cnf Link to mysqld.cnf


/etc/alternatives/my.cnf
mysqldump.cnf
Storage Engine Details that you are using
Select engine,
Count (*) as tables,
concat(round(sum(table_rows)/1000000,2),’M’) rows,
concat(round(sum(data_length)/1024*1024*1024,2),’G’) DATA,
concat(round(sum(index_length)/1024*1024*1024,2),’G’) idx,
concat(round(sum(data_length + index_length)/1024*1024*1024,2),’M’) total_size,
round(sum(index_length)/sum(data_length),2) idxfrac
From information_Schema.TABLES
Where table_schema not in (‘mysql’,’performance_schema’, ‘information_schema’)
Group by engine
Order By sum(data_length + index_length) Desc Limit 10

Storage Engine Details that you are using


Select engine,
concat(table_schema,’.’,table_name) tbl,
concat(round(sum(table_rows)/1000000,2),’M’) rows,
concat(round(sum(data_length)/1024*1024*1024,2),’G’) DATA,
concat(round(sum(index_length)/1024*1024*1024,2),’G’) idx,
concat(round(sum(data_length + index_length)/1024*1024*1024,2),’M’) total_size,
round(sum(index_length)/sum(data_length),2) idxfrac
From information_Schema.TABLES
Where table_schema not in (‘mysql’,’performance_schema’, ‘information_schema’)
And engine=‘MyISAM’  Check with innodb here
Order By data_length+ index_length Desc Limit
Converting each table to InnoDB
SET @DB_NAME = ‘your database’;

Select concat (‘Alter Table `’, table_name , ’` ENGINE=InnoDB’) as SQL Statements


From information_Schema.TABLES as tb
Where table_schema =@DB_NAME
And Table_Type=‘Base_Table’
Order By table_name desc

MySQL Tuning Tools


pt-stalk
Tuning Primer
https://github.com/RootService/tuning-primer
Buffer pool
MySQLTuner
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf https://github.com/major/MySQLTuner-perl
add in this at the bottom of the file

innodb_buffer_pool_size = 8G
query_cache_size – Specifies the size of the cache of MySQL queries waiting
to run. The recommendation is to start with small values around 10MB and
then increase to no more than 100-200MB. With too many cached queries,
max_connection – Refers to the number of connections allowed into
you can experience a cascade of queries “Waiting for cache lock.” If your
the database. If you’re getting errors citing “Too many connections,”
queries keep backing up, a better procedure is to use EXPLAIN to evaluate
increasing this value may help.
each query and find ways to make them more efficient.

query_cache_size max_connection

my.cnf

innodb_buffer_pool_size innodb_io_capacity

innodb_buffer_pool_size – This setting allocates system memory as a data innodb_io_capacity – This variable sets the rate for input/output
cache for your database. If you have large chunks of data, increase this from your storage device. This is directly related to the type and
value. Take note of the RAM required to run other system resources. speed of your storage drive. A 5400-rpm HDD will have a much
lower capacity than a high-end SSD or Intel Optane. You can adjust
this value to better match your hardware.

You might also like