Home > Database > Mysql Tutorial > mysql 优化技巧心得一(key

mysql 优化技巧心得一(key

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:40:34
Original
1306 people have browsed it

1: 对于mysql来说,登录的时候,加一个参数 #mysql -u root -p --prompt=\\u@\\d \\r:\\m:\\s --prompt 是加一些登录后的参数,上面参数 u 是加入登录的用户名, d 是登录后选择后(use dbname)的数据库表, r m s 是时间 2: key_buffer_size 对MyISAM表性能影响很

1: 对于mysql来说,登录的时候,加一个参数

#mysql -u root -p --prompt="\\u@\\d \\r:\\m:\\s>"
Copy after login

--prompt 是加一些登录后的参数,上面参数 u 是加入登录的用户名, d 是登录后选择后(use dbname)的数据库表, r m s 是时间


2: key_buffer_size 对MyISAM表性能影响很大.

mysql> show variables like 'key_buffer_size';
+-----------------+------------+
| Variable_name | Value |
+-----------------+------------+
| key_buffer_size | 536870912 |
+-----------------+------------+
Copy after login

分配了512MB内存给mysql key_buffer_size,我们再看一下key_buffer_size的使用情况:
mysql> show global status like 'key_read%';
+------------------------+-------------+
| Variable_name | Value |
+------------------------+-------------+
| Key_read_requests | 27813678764 |
| Key_reads | 6798830 |
+------------------------+-------------+
Copy after login

一共有27813678764个索引读取请求,有6798830个请求在内存中没有找到直接从硬盘读取索引,计算索引未命中缓存的概率:

key_cache_miss_rate = Key_reads / Key_read_requests * 100%

比如上面的数据,key_cache_miss_rate为0.0244%,4000个索引读取请求才有一个直接读硬盘,已经很BT了,key_cache_miss_rate在0.1%以下都很好(每1000个请求有一个直接读硬盘),如果key_cache_miss_rate在0.01%以下的话,key_buffer_size分配的过多,可以适当减少。
MySQL服务器还提供了key_blocks_*参数:
mysql> show global status like 'key_blocks_u%';
+------------------------+-------------+
| Variable_name | Value |
+------------------------+-------------+
| Key_blocks_unused | 0 |
| Key_blocks_used | 413543 |
+------------------------+-------------+
Copy after login

Key_blocks_unused表示未使用的缓存簇(blocks)数,Key_blocks_used表示曾经用到的最大的blocks数,比如这台服务器,所有的缓存都用到了,要么增加key_buffer_size,要么就是过渡索引了,把缓存占满了。比较理想的设置:


Key_blocks_used / (Key_blocks_unused + Key_blocks_used) * 100% ≈ 80%

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template