Created
February 8, 2017 19:02
-
-
Save JCotton1123/f0fe955bcb242cf74e198bb0c4541555 to your computer and use it in GitHub Desktop.
mysql tuning queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Database size | |
SELECT table_schema "Data Base Name", | |
sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB", | |
sum( data_free )/ 1024 / 1024 "Free Space in MB" | |
FROM information_schema.TABLES | |
GROUP BY table_schema ; | |
# Size of each non-primary index | |
SELECT database_name, table_name, index_name, | |
round(stat_value*@@innodb_page_size/1024/1024, 2) size_in_mb | |
FROM mysql.innodb_index_stats | |
WHERE stat_name = 'size' AND index_name != 'PRIMARY' | |
ORDER BY 4 DESC; | |
# Total size of non-primary indexes | |
SELECT sum(round(stat_value*@@innodb_page_size/1024/1024, 2)) size_in_mb | |
FROM mysql.innodb_index_stats | |
WHERE stat_name = 'size' AND index_name != 'PRIMARY'; | |
# Actual GB of memory is in use by InnoDB Data in the InnoDB Buffer Pool | |
SELECT (PagesData*PageSize)/POWER(1024,3) DataGB FROM | |
(SELECT variable_value PagesData | |
FROM information_schema.global_status | |
WHERE variable_name='Innodb_buffer_pool_pages_data') A, | |
(SELECT variable_value PageSize | |
FROM information_schema.global_status | |
WHERE variable_name='Innodb_page_size') B; | |
# Recommended innodb_buffer_pool_size (includes 60% for growth) | |
SELECT CEILING(Total_InnoDB_Bytes*1.6/POWER(1024,3)) RIBPS FROM | |
(SELECT SUM(data_length+index_length) Total_InnoDB_Bytes | |
FROM information_schema.tables WHERE engine='InnoDB') A; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment