`

MySQL -- 内存使用监控详解

 
阅读更多
第一步: 配置performance_schema使它开启内存方面的监控
 在/etc/my.cnf中增加如下内容
引用
####  for performance_schema
performance_schema                                                      =on    #    on
performance_schema_consumer_events_stages_current                       =on    #    off
performance_schema_consumer_events_stages_history                       =on    #    off
performance_schema_consumer_events_stages_history_long                  =off   #    off
performance_schema_consumer_statements_digest                           =on    #    on
performance_schema_consumer_events_statements_current                   =on    #    on
performance_schema_consumer_events_statements_history                   =on    #    on
performance_schema_consumer_events_statements_history_long              =off   #    off
performance_schema_consumer_events_waits_current                        =on    #    off
performance_schema_consumer_events_waits_history                        =on    #    off
performance_schema_consumer_events_waits_history_long                   =off   #    off
performance_schema_consumer_global_instrumentation                      =on    #    on
performance_schema_consumer_thread_instrumentation                      =on    #    on
performance-schema-instrument                                           ='memory/%=COUNTED'


第二步:重启mysql数据库
引用
systemctl restart mysql


第三步:通过performance_schema查询内存的使用情况
引用
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             | 1.47 GiB      |
| memory/performance_schema | 131.51 MiB    |
| memory/mysys              | 8.22 MiB      |
| memory/sql                | 3.19 MiB      |
| memory/memory             | 213.15 KiB    |
| memory/myisam             | 171.79 KiB    |
| memory/csv                | 512 bytes     |
| memory/blackhole          | 512 bytes     |
+---------------------------+---------------+
8 rows in set (0.00 sec)

https://www.cnblogs.com/JiangLe/p/8663032.html

https://github.com/Neeky/mysqltools/blob/master/deploy/ansible/mysql/template/5.7/my.cnf

https://akingde.iteye.com/blog/1856545
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics