MySQL内存使用查看方式

使用版本:MySQL 5.7

在performance_schema有如下表记录内存使用情况

mysql> show tables like ‘%memory%summary%‘;
+-------------------------------------------------+
| Tables_in_performance_schema (%memory%summary%) |
+-------------------------------------------------+
| memory_summary_by_account_by_event_name         |
| memory_summary_by_host_by_event_name            |
| memory_summary_by_thread_by_event_name          |
| memory_summary_by_user_by_event_name            |
| memory_summary_global_by_event_name             |
+-------------------------------------------------+

每个内存统计表都有如下统计列: 

* COUNT_ALLOC,COUNT_FREE:对内存分配和释放内存函数的调用总次数

* SUM_NUMBER_OF_BYTES_ALLOC,SUM_NUMBER_OF_BYTES_FREE:已分配和已释放的内存块的总字节大小

* CURRENT_COUNT_USED:这是一个便捷列,等于COUNT_ALLOC - COUNT_FREE

* CURRENT_NUMBER_OF_BYTES_USED:当前已分配的内存块但未释放的统计大小。这是一个便捷列,等于SUM_NUMBER_OF_BYTES_ALLOC - SUM_NUMBER_OF_BYTES_FREE

* LOW_COUNT_USED,HIGH_COUNT_USED:对应CURRENT_COUNT_USED列的低和高水位标记

* LOW_NUMBER_OF_BYTES_USED,HIGH_NUMBER_OF_BYTES_USED:对应CURRENT_NUMBER_OF_BYTES_USED列的低和高水位标记

内存统计表允许使用TRUNCATE TABLE语句。使用truncate语句时有如下行为: 

* 通常,truncate操作会重置统计信息的基准数据(即清空之前的数据),但不会修改当前server的内存分配等状态。也就是说,truncate内存统计表不会释放已分配内存

* 将COUNT_ALLOC和COUNT_FREE列重置,并重新开始计数(等于内存统计信息以重置后的数值作为基准数据)

* SUM_NUMBER_OF_BYTES_ALLOC和SUM_NUMBER_OF_BYTES_FREE列重置与COUNT_ALLOC和COUNT_FREE列重置类似

* LOW_COUNT_USED和HIGH_COUNT_USED将重置为CURRENT_COUNT_USED列值

*  LOW_NUMBER_OF_BYTES_USED和HIGH_NUMBER_OF_BYTES_USED将重置为CURRENT_NUMBER_OF_BYTES_USED列值

* 此外,按照帐户,主机,用户或线程分类统计的内存统计表或memory_summary_global_by_event_name表,如果在对其依赖的accounts、hosts、users表执行truncate时,会隐式对这些内存统计表执行truncate语句

简单来说,就是可以根据用户、主机、线程、账号、全局的维度对内存进行监控。同时库sys也就这些表做了进一步的格式化,可以使得用户非常容易的观察到每个对象的内存开销:

mysql> select event_name,current_alloc from sys.memory_global_by_current_bytes limit 10;
+-----------------------------------------------------------------------------+---------------+
| event_name                                                                  | current_alloc |
+-----------------------------------------------------------------------------+---------------+
| memory/performance_schema/events_statements_history_long                    | 13.66 MiB     |
| memory/performance_schema/events_statements_history_long.sqltext            | 9.77 MiB      |
| memory/performance_schema/events_statements_history_long.tokens             | 9.77 MiB      |
| memory/performance_schema/events_statements_summary_by_digest.tokens        | 9.77 MiB      |
| memory/performance_schema/table_handles                                     | 9.06 MiB      |
| memory/performance_schema/events_statements_summary_by_thread_by_event_name | 8.67 MiB      |
| memory/sql/String::value                                                    | 6.02 MiB      |
| memory/performance_schema/memory_summary_by_thread_by_event_name            | 5.62 MiB      |
| memory/performance_schema/events_statements_summary_by_digest               | 4.88 MiB      |
| memory/sql/TABLE                                                            | 4.35 MiB      |
+-----------------------------------------------------------------------------+---------------+

默认情况下performance_schema只对performance_schema进行了内存开销的统计。根据你的MySQL安装代码区域可能包括performance_schema、sql、client、innodb、myisam、csv、memory、blackhole、archive、partition和其他。

查看innodb相关的内存监控是否开启,默认不开启

mysql> SELECT * FROM performance_schema.setup_instruments
    -> WHERE NAME LIKE ‘%memory%‘;
+--------------------------------------------------------------------------------+---------+-------+
| NAME                                                                           | ENABLED | TIMED |
+--------------------------------------------------------------------------------+---------+-------+
| memory/performance_schema/mutex_instances                                      | YES     | NO    |
| memory/performance_schema/rwlock_instances                                     | YES     | NO    |
| memory/performance_schema/cond_instances                                       | YES     | NO    |
| memory/performance_schema/file_instances                                       | YES     | NO    |
| memory/performance_schema/socket_instances                                     | YES     | NO    |
| memory/performance_schema/metadata_locks                                       | YES     | NO    |
| memory/performance_schema/file_handle                                          | YES     | NO    |
| memory/performance_schema/accounts                                             | YES     | NO    |
| memory/performance_schema/events_waits_summary_by_account_by_event_name        | YES     | NO    |
| memory/performance_schema/events_stages_summary_by_account_by_event_name       | YES     | NO    |
| memory/performance_schema/events_statements_summary_by_account_by_event_name   | YES     | NO    |
| memory/performance_schema/events_transactions_summary_by_account_by_event_name | YES     | NO    |
| memory/performance_schema/memory_summary_by_account_by_event_name              | YES     | NO    |
| memory/performance_schema/events_stages_summary_global_by_event_name           | YES     | NO    |
| memory/performance_schema/events_statements_summary_global_by_event_name       | YES     | NO    |
| memory/performance_schema/memory_summary_global_by_event_name                  | YES     | NO    |
| memory/performance_schema/hosts                                                | YES     | NO    |
| memory/performance_schema/events_waits_summary_by_host_by_event_name           | YES     | NO    |
| memory/performance_schema/events_stages_summary_by_host_by_event_name          | YES     | NO    |
| memory/performance_schema/events_statements_summary_by_host_by_event_name      | YES     | NO    |
| memory/performance_schema/events_transactions_summary_by_host_by_event_name    | YES     | NO    |

可以通过条件缩小范围:

mysql> SELECT * FROM performance_schema.setup_instruments
       WHERE NAME LIKE ‘%memory/innodb%‘;
+-------------------------------------------+---------+-------+
| NAME                                      | ENABLED | TIMED |
+-------------------------------------------+---------+-------+
| memory/innodb/adaptive hash index         | NO      | NO    |
| memory/innodb/buf_buf_pool                | NO      | NO    |
| memory/innodb/dict_stats_bg_recalc_pool_t | NO      | NO    |
| memory/innodb/dict_stats_index_map_t      | NO      | NO    |
| memory/innodb/dict_stats_n_diff_on_level  | NO      | NO    |
| memory/innodb/other                       | NO      | NO    |
| memory/innodb/row_log_buf                 | NO      | NO    |
| memory/innodb/row_merge_sort              | NO      | NO    |
| memory/innodb/std                         | NO      | NO    |
| memory/innodb/trx_sys_t::rw_trx_ids       | NO      | NO    |

对所有可能的对象进行内存监控。因此,还需要做下面的设置:

mysql> update performance_schema.setup_instruments set enabled = ‘yes‘ where name like ‘memory%‘;
Query OK, 306 rows affected (0.00 sec)
Rows matched: 376  Changed: 306  Warnings: 0

但是这种在线打开内存统计的方法仅对之后新增的内存对象有效:

如想要对全局生命周期中的对象进行内存统计,必须在配置文件中进行设置,然后重启:

[mysqld]
performance-schema-instrument=‘memory/%=COUNTED‘

可以使用sys库下的memory_global_by_current_bytes表来查询相同的底层数据,该模式表显示了全局服务器内当前内存使用情况,按分配类型进行细分。

mysql> SELECT * FROM sys.memory_global_by_current_bytes
       WHERE event_name LIKE ‘memory/innodb/buf_buf_pool‘\G
*************************** 1. row ***************************
       event_name: memory/innodb/buf_buf_pool
    current_count: 1
    current_alloc: 131.06 MiB
current_avg_alloc: 131.06 MiB
       high_count: 1
       high_alloc: 131.06 MiB
   high_avg_alloc: 131.06 MiB

此sys模式查询通过current_alloc()代码区域聚合当前分配的内存:

mysql> SELECT SUBSTRING_INDEX(event_name,‘/‘,2) AS
       code_area, sys.format_bytes(SUM(current_alloc))
       AS current_alloc
       FROM sys.x$memory_global_by_current_bytes
       GROUP BY SUBSTRING_INDEX(event_name,‘/‘,2)
       ORDER BY SUM(current_alloc) DESC;
+---------------------------+---------------+
| code_area                 | current_alloc |
+---------------------------+---------------+
| memory/innodb             | 843.24 MiB    |
| memory/performance_schema | 81.29 MiB     |
| memory/mysys              | 8.20 MiB      |
| memory/sql                | 2.47 MiB      |
| memory/memory             | 174.01 KiB    |
| memory/myisam             | 46.53 KiB     |
| memory/blackhole          | 512 bytes     |
| memory/federated          | 512 bytes     |
| memory/csv                | 512 bytes     |
| memory/vio                | 496 bytes     |
+---------------------------+---------------+

原文地址:https://www.cnblogs.com/grasp/p/10306697.html

时间: 2024-10-23 17:42:03

MySQL内存使用查看方式的相关文章

内存的分配方式

一.内存的分配方式 程序占用的内存分为五个区域: 1.静态区/全局区(static)存放静态变量.全局变量,内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间始终不变.2.栈区(stack)存放函数的参数值.局部变量的值等,由编译器自动分配释放.管理简单,空间使用效率高,但是生命周期很短暂,分配的内存容量有限.用来存储函数的参数和非静态局部变量.3.堆区(heap)也叫动态内存分配.程序在运行的时候new申请任意大小的内存,一般由程序员分配释放,如果程序员没有释放掉,程序会一直占用内

MySQL内存分配

原文链接: MySQL Memory Allocation -- by Rick James 原文日期: Created 2010; Refreshed Oct, 2012, Jan, 2014 翻译人员: 铁锚 翻译日期: 2014年5月28日 MySQL 内存分配-- 快速设置方案 如果仅使用MyISAM存储引擎,设置 key_buffer_size 为可用内存的20%,(再加上设置 innodb_buffer_pool_size = 0 ) 如果仅使用InnoDB存储引擎,设置 innod

mysql内存参数整理和条调优以及内存统计

date:20140530auth:Jin 参考:http://dev.mysql.com/doc/refman/5.5/en/server-status-variables.html#http://dev.mysql.com/doc/refman/5.5/en/memory-use.htmlhttp://blog.csdn.net/wyzxg/article/details/7268122http://blog.csdn.net/wyzxg/article/details/7268175 *.

Mysql内存表配置及性能测试

centos7 mysql数据库安装和配可以参考一下文章,基本照做就可以了(我选的方法二): http://www.cnblogs.com/starof/p/4680083.html 说到内存表,首先有两个概念简单区分下: 1.临时表:2.内存表: 临时表与内存表的区分: 临时表是指使用create temprary table创建的临时表.临时表可以使用任何存储引擎,临时表只在单个连接中可见,当连接断开时,临时表也会消失. MySQL最初会将临时表创建在内存中,当数据变的太大后,就会转储到磁盘

MySQL内存调优

原文链接: MySQL Memory Allocation -- by Rick James原文日期: Created 2010; Refreshed Oct, 2012, Jan, 2014 翻译人员: 铁锚翻译日期: 2014年5月28日 MySQL 内存分配-- 高速设置方案假设仅使用MyISAM存储引擎,设置 key_buffer_size为可用内存的20%,(再加上设置 innodb_buffer_pool_size = 0 ) 假设仅使用InnoDB存储引擎,设置 innodb_bu

mysql常见性能查看命令

登陆mysql: mysql –u用户名 –p密码 [-h 主机名或IP]  ##远程登陆需要加选项-h 查看: show  databases; ##查看数据库 use mysql;   ##进入数据库mysql show tables;  ##查看表 desc user;  ##查看表的结构,表头 select * from  user \G; ##查询user表中的所有数据记录 select host,user,passwordfrom user;  ##指定user表的字段进行查询 sh

jmeter内存溢出处理方式记录

空间管理您的位置: 51Testing软件测试网 » ayuyua的个人空间 » 日志 jmeter内存溢出处理方式记录 上一篇 / 下一篇  2014-09-24 11:26:43 / 个人分类:jmeter学习 查看( 6 ) / 评论( 0 ) / 评分( 0 / 0 ) 使用jmeter进行压力测试时遇到一段时间后报内存溢出outfmenmory错误,导致jmeter卡死了,先尝试在jmeter.bat中增加了JVM_ARGS="-Xmx2048m -Xms2048m -Xmn256m

18、MySQL内存体系架构及参数总结

内存结构: Mysql 内存分配规则是:用多少给多少,最高到配置的值,不是立即分配 图只做大概参考 全局缓存包括: global buffer(全局内存分配总和) = innodb_buffer_pool_size                      -- InnoDB高速缓冲,行数据.索引缓冲,以及事务锁.自适应哈希等 +innodb_additional_mem_pool_size    -- InnoDB数据字典额外内存,缓存所有表数据字典 +innodb_log_buffer_si

CentOS下内存使用率查看

freetotal        used        free      shared     buffers      cachedMem:        1815340     1628680      186660           0      130316     1327736-/+ buffers/cache:      170628     1644712Swap:       1020116           0     1020116Mem:表示物理内存统计-/+ b