针对完全静态数据库的 MySQL 优化技巧?

发布于 2024-11-13 11:25:57 字数 188 浏览 1 评论 0原文

我有一个大约 20 GB 大小的数据库。我想知道是否有任何专门针对静态数据库的优化技巧。当我说静态时,我并不是指不经常改变,而是指根本不会改变。是否有任何极端的值设置或其他通常您在易失性数据库中远离的东西,可以使真正的静态数据库受益?特别是考虑到只有 SELECT 语句而绝对没有 INSERT 语句?我正在使用 MyISAM 表。

——罗施勒

I have a database that is about 20 GB in size. I want to know if there are any optimization tips specific to working with a database that is static. When I mean static, I don't mean changes infrequently, I mean won't change at all. Are there any extreme settings for values or other things that normally you stay away from with a volatile database, that can benefit a truly static database; especially considering there will only be SELECT statements and absolutely no INSERT statements? I'm using MyISAM tables.

-- roschler

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想挽留 2024-11-20 11:25:57

由于一切都是MyISAM,因此您需要关注两件主要的事情:

KEY CACHE

用于缓存的主要机制是密钥缓存。它仅缓存 .MYI 文件中的索引页。要调整密钥缓存的大小,请运行以下查询:

SELECT CONCAT(ROUND(KBS/POWER(1024,IF(PowerOfTwo<0,0,IF(PowerOfTwo>3,0,PowerOfTwo)))+0.4999),
SUBSTR(' KMG',IF(PowerOfTwo<0,0,IF(PowerOfTwo>3,0,PowerOfTwo))+1,1)) recommended_key_buffer_size
FROM (SELECT LEAST(POWER(2,32),KBS1) KBS FROM
(SELECT SUM(index_length) KBS1 FROM information_schema.tables
WHERE engine='MyISAM' AND table_schema NOT IN ('information_schema','mysql')) AA) A,
(SELECT 2 PowerOfTwo) B;

这将为给定当前数据集的 MyISAM 密钥缓存 (key_buffer_size) 提供推荐设置 (查询会将建议上限设置为 4G (4096M))。对于 32 位操作系统,4GB 是限制。对于 64 位,8GB。

全文索引

您应该更改停用词列表。您可能想要更改停用词,因为 MySQL 不会索引此列表共 643 个字。尝试创建您自己的停用词列表并更改最小单词长度。

步骤 1) 创建您自己的停用词列表。您可以添加“a”、“an”和“the”。

echo "a" > /var/lib/mysql/custom_stopwords.txt<BR>
echo "an" >> /var/lib/mysql/custom_stopwords.txt<BR>
echo "the" >> /var/lib/mysql/custom_stopwords.txt

步骤 2) 将这些选项添加到 /etc/my.cnf

ft_min_word_len=2
ft_stopword_file=/var/lib/mysql/custom_stopwords.txt

步骤 3) service mysql restart

步骤 4) 创建新的 FULLTEXT 索引。重新启动 mysql 之前应重新索引任何现有的 FULLTEXT 索引。

尝试一下这些想法!

Since everything is MyISAM, you need to focus on two major things:

KEY CACHE

The main mechanism used for caching is the key cache. It only caches index pages from .MYI files. To size your key cache, run the following query:

SELECT CONCAT(ROUND(KBS/POWER(1024,IF(PowerOfTwo<0,0,IF(PowerOfTwo>3,0,PowerOfTwo)))+0.4999),
SUBSTR(' KMG',IF(PowerOfTwo<0,0,IF(PowerOfTwo>3,0,PowerOfTwo))+1,1)) recommended_key_buffer_size
FROM (SELECT LEAST(POWER(2,32),KBS1) KBS FROM
(SELECT SUM(index_length) KBS1 FROM information_schema.tables
WHERE engine='MyISAM' AND table_schema NOT IN ('information_schema','mysql')) AA) A,
(SELECT 2 PowerOfTwo) B;

This will give the Recommended Setting for MyISAM Key Cache (key_buffer_size) given your current data set (the query will cap the recommendation at 4G (4096M)).For 32-bit OS, 4GB is the limit. For 64-bit, 8GB.

FULLTEXT Indexes

You should change the stopword list. You may want to change the stop words because MySQL will not index this list of 643 words. Try creating your own stopword list and changing the min word length.

Step 1) Create a stop word list of your own. You could add 'a','an', and 'the'.

echo "a" > /var/lib/mysql/custom_stopwords.txt<BR>
echo "an" >> /var/lib/mysql/custom_stopwords.txt<BR>
echo "the" >> /var/lib/mysql/custom_stopwords.txt

Step 2) Add these options to /etc/my.cnf

ft_min_word_len=2
ft_stopword_file=/var/lib/mysql/custom_stopwords.txt

Step 3) service mysql restart

Step 4) Create new FULLTEXT indexes. Any existing FULLTEXT indexes before restart of mysql should be reindexed.

Give These Ideas a Try !!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文