欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

對MySQL性能優(yōu)化的簡單辦法是怎樣的

對MySQL性能優(yōu)化的簡單辦法是怎樣的,針對這個問題,這篇文章詳細介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

成都創(chuàng)新互聯(lián)公司憑借專業(yè)的設(shè)計團隊扎實的技術(shù)支持、優(yōu)質(zhì)高效的服務(wù)意識和豐厚的資源優(yōu)勢,提供專業(yè)的網(wǎng)站策劃、網(wǎng)站設(shè)計制作、網(wǎng)站制作、網(wǎng)站優(yōu)化、軟件開發(fā)、網(wǎng)站改版等服務(wù),在成都十多年的網(wǎng)站建設(shè)設(shè)計經(jīng)驗,為成都近1000家中小型企業(yè)策劃設(shè)計了網(wǎng)站。

對擁有一個幾十萬行表的 MySQL 性能優(yōu)化的簡單辦法(轉(zhuǎn))[@more@]數(shù)據(jù)庫的優(yōu)化大概是在系統(tǒng)管理中最具有挑戰(zhàn)性的了,因為其對人員的素質(zhì)要求幾乎是全方面的,好的 DBA 需要各種綜合素質(zhì)。在排除了操作系統(tǒng),應(yīng)用等引起的性能問題以外,優(yōu)化數(shù)據(jù)庫最核心的實際上就是配置參數(shù)的調(diào)整。本文通過一個簡單的參數(shù)調(diào)整,實現(xiàn)了對擁有一個幾十萬行表的 group by 優(yōu)化的例子。通過這個簡單的調(diào)整,數(shù)據(jù)庫性能有了突飛猛進的提升。
本例子是針對 MySQL 調(diào)整的,不像其他商業(yè)數(shù)據(jù)庫,MySQL 沒有視圖,特別是 Oracle 可以利用固化視圖來提升查詢性能,沒有存儲過程,因此性能的調(diào)整幾乎只能通過配置合適的參數(shù)來實現(xiàn)。

調(diào)整的具體步驟(例子針對 pLog 0.3x 的博客系統(tǒng)):

發(fā)現(xiàn)最多的 slow log 是:
SELECT category_id, COUNT(*) AS 'count' FROM plog_articles WHERE blog_id = 2 AND status = 'PUBLISHED' group by category_id;
一般在 20s 以上,甚至 30s 。
而當 blog_id=1 或者其他時,都能很快的選出結(jié)果。
于是懷疑索引有問題,重新建立索引,但無濟于事。 EXPLAIN 結(jié)果如下:
mysql> EXPLAIN SELECT category_id, COUNT(*) AS 'count' FROM plog_articles WHERE blog_id = 2 AND status = 'PUBLISHED' group by category_id;
+---------------+------+------------------+------------------+---------+-------------+------+----------------------------------------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+---------------+------+------------------+------------------+---------+-------------+------+----------------------------------------------+
| plog_articles | ref | idx_article_blog | idx_article_blog | 5 | const,const | 4064 | Using where; Using temporary; Using filesort |
+---------------+------+------------------+------------------+---------+-------------+------+----------------------------------------------+
1 row in set (0.00 sec)

于是想到每次查看 blog_id = 2 的博客時,系統(tǒng)負載就提高,有較高的 swap 。于是查看 temporary table 有關(guān)的資料,果然有這樣的說法:

If you create a lot of disk-based temporary tables, increase the size of tmp_table_size if you can do so safely. Keep in mind that setting the value too high may result in excessive swapping or MySQL running out of memory if too many threads attempt to allocate in-memory temporary tables at the same time. Otherwise, make sure that tmpdir points to a very fast disk that's not already doing lots of I/O.
Another problem that doesn't show up in the slow query log is an excessive use of disk-based temporary tables. In the output of EXPLAIN, you'll often see Using temporary. It indicates that MySQL must create a temporary table to complete the query. However, it doesn't tell you whether that temporary table will be in memory or on disk. That's controlled by the size of the table and MySQL's tmp_table_size variable.
If the space required to build the temporary table is less than or equal to tmp_table_size, MySQL keeps it in memory rather than incur the overhead and time required to write the data to disk and read it again. However, if the space required exceeds tmp_table_size, MySQL creates a disk-based table in its tmpdir directory (often /tmp on Unix systems.) The default tmp_table_size size is 32 MB.
To find out how often that happens, compare the relative sizes of the Created_tmp_tables and Created_tmp_disk_tables counters:

調(diào)整 tmp_table_size為 80M 左右后,以上語句 14s 即可解決。

這個參數(shù)是 DBA 很容易忽視的。

其實,不單單是數(shù)據(jù)庫,就是操作系統(tǒng),也是受 tmp 的影響巨大,例如安裝軟件到 d: 盤,如果 TMP 環(huán)境變量指向 c: 盤,而 c: 空間不夠,照樣可能導(dǎo)致安裝失敗。

因此讓 TMP 有足夠的空間可以說是計算機系統(tǒng)里一個普遍適用的原則(寫程序也是一樣)。

關(guān)于對MySQL性能優(yōu)化的簡單辦法是怎樣的問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。

網(wǎng)頁標題:對MySQL性能優(yōu)化的簡單辦法是怎樣的
標題URL:http://chinadenli.net/article40/pgphho.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)定制網(wǎng)站、虛擬主機網(wǎng)站策劃、企業(yè)網(wǎng)站制作面包屑導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作