mysql 簡單最佳化方法

來源:互聯網
上載者:User

標籤:io   使用   for   檔案   資料   on   問題   時間   as   

最佳化步驟:
1、查看SQL是否可以最佳化。
2、查看索引是否可以最佳化。
3、查看錶結構是否可以最佳化。

show table status from databases like ‘tablename%‘; // 查看錶的容量、索引和資料檔案的大小

show processlist; // 查看當前連結情況。
explain sql \G // 查看SQL使用的索引的情況。
當確認索引使用沒有問題的時候可以查看當前SQL的佔用cpu、io等情況。
set profiling=on;
run sql;
show profiles ;// get query id
show profile cpu, block io for query id; // 查看CPU、IO的使用方式。

常用方法:
1、當發現SQL使用了索引,但是索引使用不正確的時候可以強制使用別的索引 ... force index(index_name) from table_name;
2、針對使用索引(單表查詢)且含有OR或者IN操作的SQL可以使用 UNION ALL 這樣基本上可以節約大約1/2至2/3的時間。
3、只SELECT 使用到的列。

mysql 簡單最佳化方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.