您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“如何定位并優(yōu)化慢查詢sql”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“如何定位并優(yōu)化慢查詢sql”吧!
mysql> show variables like "%query%"; +------------------------------+-------------------------------------------------+ | Variable_name | Value | +------------------------------+-------------------------------------------------+ | binlog_rows_query_log_events | OFF | | ft_query_expansion_limit | 20 | | have_query_cache | YES | | long_query_time | 10.000000 | 查詢時間 | query_alloc_block_size | 8192 | | query_cache_limit | 1048576 | | query_cache_min_res_unit | 4096 | | query_cache_size | 1048576 | | query_cache_type | OFF | | query_cache_wlock_invalidate | OFF | | query_prealloc_size | 8192 | | slow_query_log | OFF | . 慢日志是否打開 | slow_query_log_file | /usr/local/mysql/data/tandeMacBook-Pro-slow.log | 慢日志log位置 +------------------------------+-------------------------------------------------+ mysql> set global show_query_log = on; 開啟慢查詢?nèi)罩荆ㄗ詈脤懺谂渲梦募? mysql> set global long_query_time = 1; 設置慢日志查詢時間 mysql> show status like "%slow_queries%"; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Slow_queries | 0 | 慢查詢出現(xiàn)的次數(shù) +---------------+-------+
mysql> explain select * from t_employee where name = "汪燕"; +----+-------------+------------+------------+------+-------------------+-------------------+---------+-------+------+----------+-------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+------------+------------+------+-------------------+-------------------+---------+-------+------+----------+-------+ | 1 | SIMPLE | t_employee | NULL | ref | idx_employee_name | idx_employee_name | 50 | const | 1 | 100.00 | NULL | +----+-------------+------------+------------+------+-------------------+-------------------+---------+-------+------+----------+-------+
到此,相信大家對“如何定位并優(yōu)化慢查詢sql”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關內(nèi)容可以進入相關頻道進行查詢,關注我們,繼續(xù)學習!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。