暂无图片
暂无图片
暂无图片
暂无图片
暂无图片
mysql性能优化参数.txt
536
10页
49次
2021-02-24
免费下载
mysql 的监控方法大致分为两类:
1.连接到 mysql 数据库内部,使用 show statusshow variablesflush status 来查看 mysql
各种性能指标。
2. 直接使用 mysqladmin 查看其性能指标,例如:
UserParameter=mysql.uptime,mysqladmin -uroot status|cut -f2 -d":"|cut -f1 -d"T"
mysqladmin 两个参数,statusextended-status
shell > mysqladmin -uroot -ppassword variables status
可得到以下信息(后面详解)
--------------------------------------------------------------------------------
------------------------------------------
Uptime: 4557887 #mysql 运行的秒数
Threads: 1 #连接数
Questions: 1684130 #The number of questions (queries) from clients since the
server was started.
Slow queries: 0 #The number of queries that have taken more than
long_query_time seconds
Opens: 221872 #The number of tables the server has opened.
Flush tables: 1 #The number of flush-*, refresh, and reload commands the
server has executed.
Open tables: 64 #The number of tables that currently are open.
Queries per second avg: 0.369 #从上次运行开始计算,每秒钟平均查询次数
--------------------------------------------------------------------------------
---------------------
Questions = Com_* + Qcache_hits
最完整的信息
shell > mysqladmin -uroot -ppassword variables extended-status
其他的信息
shell > /usr/libexec/mysqld --verbose --help (这个命令生成所有 mysqld 选项和可配置变量
的列表 )
mysql>SHOW STATUS; (服务器状态变量,运行服务器的统计和状态指标)
mysql> SHOW VARIABLES;(服务器系统变量,实际上使用的变量的值)
或者
mysql>SHOW STATUS LIKE '%变量名% ' ;
对配置参数的说明:
配置参数的格式如下:(shell > mysqladmin -uroot -ppassword variables extended-
status
-----------------------------
+-----------------------------------------
+------------------------------------------------------------+
| Variable_name | Value
|
+-----------------------------------------
+------------------------------------------------------------+
| auto_increment_increment | 1
|
| auto_increment_offset | 1
|
| automatic_sp_privileges | ON
|
.........
注:value 值的单位是 byte ,要得到 M ,需除以 2 1024
-----------------------------------
Uptime 4405546
MySQL 服务器已经运行的秒数
-----------------------------------
auto_increment_increment 1
auto_increment_offset 1
两个变量值都只能为 1 65,535 之间的整数值。设置为非整数值,则会给出错误。
这两个变量影响 AUTO_INCREMENT 列。
auto_increment_increment 控制列中的值的增量值(步进量)。
auto_increment_offset 确定 AUTO_INCREMENT 列值的初始值。
一般不去更改。更改方法:mysql> SET @auto_increment_offset=5;
--------------------------------------------------------------------------------
---------------------
max_connections 100
table_cache 64
open_files_limit 1024
Open_tables 64
Opened_tables 187690
几个参数的关系:
table_cache * 2 + max_connectionsmax_open_files
max_connections
默认为 100
mysql>show processlist;
mysql>show full processlist;
-----------------------
-------------------------
max_open_files open_files_limit 参数决定。
mysql 打开的最大文件数,受两个参数的影响:系统打开的最大文件数(ulimit -n)和
open_files_limit
加大 max_open_files 的值
-------------------------------------------------------------
/etc/my.cnf 加入 open_files_limit=8192
/etc/security/limits.conf 添加
* soft nofile 8192
* hard nofile 8192
--------------------------------------------------------------------
最好用 sysctl 或者修改/etc/sysctl.conf 文件,同时还要在配置文件中把 open_files_limit 这个参
数增大,对于 4G 内存服务器,open_files_limit 至少要增大到 4096,非特殊情况,设置成 8192 就可以
了。
table_cache
MySQL 5.0 升级到 5.1table_cache 改名 table_open_cache
设置表高速缓存的数目。
表缓存的说明:
Mysql 访问一个表时,如果该表在缓存中已经被打开,则可以直接访问缓存;如果还没有被缓存,但是在
Mysql 表缓冲区中还有空间,那么这个表就被打开并放入表缓冲区;如果表缓存满了,则会按照一定的规则
将当前未用的表释放,或者临时扩大表缓存来存放,使用表缓存的好处是可以更快速地访问表中的内容。
每个连接进来,都会至少打开一个表缓存。因此, table_cache 的大小应与 max_connections 的设置
有关。例如,对于 200 个并行运行的连接,应该让表的缓存至少有 200 × N ,这里 N 是网站程序一次查
询所用到的表的最大值。
每个线程会独自持有一个数据文件的文件描述符,而索引文件的文件描述符是公用的。当 table cache 不够
用的时候,MySQL 会采用 LRU 算法踢掉最长时间没有使用的表。如果 table_cache 设置过小,MySQL 就会
反复打开、关闭 frm 文件,造成一定的性能损失。如果 table_cache 设置过大,MySQL 将会消耗很多 CPU
去做 table cache 的算法运算。
InnoDB 的元数据管理是放在共享表空间里面做的,所以获取表的结构不需要去反复解 frm 文件,这是
MyISAM 的地方。使 table_cache 设置过小,对于 InnoDB 的影响是很小的,因为它根本不需要反
复打开、关闭 frm 文件去获取元数据。
理设置 table_cache 的大小:过查看 open_tablesOpened_tablesFlush tables 的值来
看当前的表缓存情况:
shell > mysqladmin -uroot -ppassword variables status
----------------------------------
Opens: 221872 则是已经打开的表的数量。
Flush tables: 1
of 10
免费下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

关注
最新上传
暂无内容,敬请期待...
下载排行榜
Top250 周榜 月榜