iT邦幫忙

0

MySQL優化(tmp_table_size、max_tmp_tables、max_heap_table_size值?)

afgn 2012-01-03 10:37:2514507 瀏覽

想請教一下,這三個值的建議設定是多少?

我的設定為:
tmp_table_size = 256M
max_tmp_tables = 32
max_heap_table_size = 2048M

但是用 MySQL 調教工具測試,發現它總是會說有 tmp table create on disk...
這樣是好還是不好? 可以讓它通通由 RAM 來建立嗎? Thx!

TEMP TABLES
Current max_heap_table_size = 2.00 G
Current tmp_table_size = 256 M
Of 595 temp tables, 30% were created on disk
Perhaps you should increase your tmp_table_size and/or max_heap_table_size
to reduce the number of disk-based temporary tables
Note! BLOB and TEXT columns are not allow in memory tables.
If you are using these columns raising these values might not impact your
ratio of on disk temp tables.

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

8
ghost
iT邦新手 2 級 ‧ 2012-01-03 17:11:01
最佳解答

不要一昧相信 test tool.
你要自己去試過一陣子,才知道改成他覺得 ok 的樣子,下場可能會是什麼.

tmp_table_size 設大,那要看你主機記憶體是不是加不用錢的.
不然哪天不小心被一個神經打結的傢伙給你來個亂七八糟存取,
或 sql query bug 被踩到,就會造成 tmp_table 卯起來吃你記憶體.
下場可能就是 server 死給你看.

你問的這些東西,基本都跟你掛的資料庫是什麼東西,幹什麼用的,怎麼寫的有關.
比如說 max_tmp_tables
正常的使用者在 UI 操作時, UI 同時最多會 ref 到幾個 tables 給 user 選?
如果是開發者透過 client 在 query 時,最多又會拉到幾個表?

如果系統是你寫的,那就問你自己.
系統是同事寫的,那就問同事,
系統是廠商寫的,那就問廠商.
隨便不知道哪裡撿來的,那就自己猜啊..

並不是隨便丟個 test tool 跑出來的數字上來,
我們就能知道你那是找外星人還是找癌細胞基因用的資料庫.
所以這樣問,沒什麼用.
(我連我公司產品用的 sql, user thread 的記憶體要配多少都不知道,
他們就只會說,看來不夠大,再 double 看看有沒有好一點...
所以我怎麼可能會知道你的資料庫參數要設多大多小才好?)

隨便舉個例.這是我機器上跑出來的.
[!!] Maximum possible memory usage: 42.5G (543% of installed RAM)
我不說的話,一定有人會嗆: 你到底懂不懂 MySQL ,會不會管啊?
你管我,我只要知道我在幹啥,有辦法讓 MySQL 不會死就好了...
(事情會這樣又不是我願意的,連 RD 都估不出他 SQL 到底要吃多少,
我只好靠自己硬幹啊...)

afgn iT邦新手 5 級 ‧ 2012-01-04 10:54:13 檢舉

請問有計算公式或是網站文件可以參考嗎?方便我們計算這些值。

我想一般程式設計師不會去算開了多少Table吧!? 最多只會關心『有多少人在連MySQL資料庫』這類的問題... 附上一些值供大家參考:

mysql> show status like '%create%';
+-------------------------+-------+
Variable_name Value
+-------------------------+-------+
Com_create_db 0
Com_create_event 0
Com_create_function 0
Com_create_index 0
Com_create_procedure0
Com_create_server 0
Com_create_table 0
Com_create_trigger 0
Com_create_udf 0
Com_create_user0
Com_create_view0
Com_show_create_db 0
Com_show_create_event 0
Com_show_create_func0
Com_show_create_proc0
Com_show_create_table 0
Com_show_create_trigger 0
Created_tmp_disk_tables 0
Created_tmp_files 44
Created_tmp_tables 0
Threads_created118
+-------------------------+-------+

ghost iT邦新手 2 級 ‧ 2012-01-04 14:45:26 檢舉
afgn iT邦新手 5 級 ‧ 2012-01-09 16:22:13 檢舉

事實上, 每一項設定值都有參考值。 請參考:http://www.fromdual.ch/sites/default/files/pt_presentation.pdf

再搭配一些工具程式去調整,自然就會有可以接受的答案。

我要發表回答

立即登入回答