1.1 前言 MySQL對於很多Linux從業者而言,是一個非常棘手的問題,多數情況都是因為對資料庫出現問題的情況和處理思路不清晰。在進行MySQL的優化之前必須要瞭解的就是MySQL的查詢過程,很多的查詢優化工作實際上就是遵循一些原則讓MySQL的優化器能夠按照預想的合理方式運行而已。 今天給大家 ...
1.1 前言 MySQL對於很多Linux從業者而言,是一個非常棘手的問題,多數情況都是因為對資料庫出現問題的情況和處理思路不清晰。在進行MySQL的優化之前必須要瞭解的就是MySQL的查詢過程,很多的查詢優化工作實際上就是遵循一些原則讓MySQL的優化器能夠按照預想的合理方式運行而已。 今天給大家體驗MySQL的優化實戰,助你高薪之路順暢。
圖 - MySQL查詢過程 1.2 優化的哲學 優化有風險,涉足需謹慎 1.2.1 優化可能帶來的問題
![](http://upload-images.jianshu.io/upload_images/7564501-1a8b830990ce9583.png)
1.2.2 優化的需求
![](http://upload-images.jianshu.io/upload_images/7564501-dfdcda2e2db12688.png)
![](http://upload-images.jianshu.io/upload_images/7564501-a675c36cf92b01fa.png)
![](http://upload-images.jianshu.io/upload_images/7564501-f5e8c1178a39d1b3.png)
![](http://upload-images.jianshu.io/upload_images/7564501-4be961f8c2c93bd1.png)
資料庫優化方面:
![](http://upload-images.jianshu.io/upload_images/7564501-63a037679e24f1c0.png)
優化選擇
![](http://upload-images.jianshu.io/upload_images/7564501-b1bdd854b444768e.png)
![](http://upload-images.jianshu.io/upload_images/7564501-e6b242a7d22da006.png)
![](http://upload-images.jianshu.io/upload_images/7564501-3ec21aec06f5b83c.png)
![](http://upload-images.jianshu.io/upload_images/7564501-b1120c8b9b93a7ba.png)
常規調優思路: 針對業務周期性的卡頓,例如在每天10-11點業務特別慢,但是還能夠使用,過了這段時間就好了。
![](http://upload-images.jianshu.io/upload_images/7564501-21f7114dbf2427f1.png)
![](http://upload-images.jianshu.io/upload_images/7564501-368857c15243c780.png)
![](http://upload-images.jianshu.io/upload_images/7564501-b45ae5d1e862e93a.png)
1.4.4 系統層面問題解決辦法 你認為到底負載高好,還是低好呢? 在實際的生產中,一般認為 cpu只要不超過90%都沒什麼問題 。 當然不排除下麵這些特殊情況: 問題一:cpu負載高,IO負載低
![](http://upload-images.jianshu.io/upload_images/7564501-21deda6a6d7b02f2.png)
![](http://upload-images.jianshu.io/upload_images/7564501-0f36fe468fe9cde1.png)
![](http://upload-images.jianshu.io/upload_images/7564501-694fb0e838e3e7b6.png)
![](http://upload-images.jianshu.io/upload_images/7564501-18d2f2ba396c9b47.png)
![](http://upload-images.jianshu.io/upload_images/7564501-832dd64d40af0713.png)
![](http://upload-images.jianshu.io/upload_images/7564501-c8d8f220153de8fb.png)
![](http://upload-images.jianshu.io/upload_images/7564501-5e21d47c9b1b088e.png)
![](http://upload-images.jianshu.io/upload_images/7564501-4608c1effe37541c.png)
![](http://upload-images.jianshu.io/upload_images/7564501-ba5dec9ec0972fa2.png)
![](http://upload-images.jianshu.io/upload_images/7564501-7e2375065be90afd.png)
![](http://upload-images.jianshu.io/upload_images/7564501-4cf7aef5821c49fd.png)
![](http://upload-images.jianshu.io/upload_images/7564501-f15f5c349ac7cf89.png)
![](http://upload-images.jianshu.io/upload_images/7564501-2e3955f6be514ad5.png)
![](http://upload-images.jianshu.io/upload_images/7564501-2e5ff603e7669684.png)
安裝圖形界面的伺服器不要啟動圖形界面 runlevel 3,另外,思考將來我們的業務是否真的需要MySQL,還是使用其他種類的資料庫。用資料庫的最高境界就是不用資料庫。 1.6 資料庫優化 SQL優化方向: 執行計劃、索引、SQL改寫 架構優化方向: 高可用架構、高性能架構、分庫分表 1.6.1 資料庫參數優化 調整: 實例整體(高級優化,擴展)
![](http://upload-images.jianshu.io/upload_images/7564501-99cb1dcf99398c48.png)
![](http://upload-images.jianshu.io/upload_images/7564501-5fadd9f1f03024f6.png)
![](http://upload-images.jianshu.io/upload_images/7564501-8e834d9311d12665.png)