2022年5月25日 星期三

Slow MySql Server Performance - What and How to check?

0

Slow MySql Server Performance - What and How to check?


Log slow queries- If your system has a ton of queries, it gets tougher to find out which queries are slowing your system. MySQL provides a tool to log slow queries for further analysis https://dev.mysql.com/doc/refman/8.0/en/slow-query-log.html


EXPLAIN Extended command shows details about your queries when your have no idea what is happening https://dev.mysql.com/doc/refman/8.0/en/explain-extended.html


To speed up your queries use Index - A good practice is add index by seeing which fields are in the WHERE clause add index for them. Also if you are retrieving all fields from a table, the query gets slower by fetching all data from disk. In SELECT query you should specify which fields you need to bring instead to bring them all with *

Not 
SELECT * FORM xTable ;

Yes
SELECT ID, Name, Addr FORM xTable ; 

Make use of Query Cache https://dev.mysql.com/doc/refman/5.7/en/query-cache-configuration.html

SHOW VARIABLES LIKE 'have_query_cache';

Make sure that your MySQL server configuration file options are optimized according to your hardware https://dev.mysql.com/doc/refman/8.0/en/option-files.html


Make sure that you are using optimized data types while creating a table structure For example "Comments" fields has size of 256 characters, reply it to MYSQL with a field with type VARCHAR(256) instead of using TEXT. The query will be much faster.



rocedure_Analyse() can help you in finding optimal data types:

http://www.mysqlperformanceblog.com/2009/03/23/procedure-analyse/

http://dev.mysql.com/doc/refman/5.0/en/procedure-analyse.html

http://dba.stackexchange.com/questions/53229/slow-mysql-server-performance-what-and-how-to-check

0 意見:

張貼留言