<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="monitor-mysql-memory-use">
      </a>
      10.12.3.2 Monitoring MySQL Memory Usage
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045222217424">
  </a>
  <a class="indexterm" name="idm46045222215936">
  </a>
  <p>
   The following example demonstrates how to use
   <a class="link" href="performance-schema.html" title="Chapter 29 MySQL Performance Schema">
    Performance Schema
   </a>
   and
   <a class="link" href="sys-schema.html" title="Chapter 30 MySQL sys Schema">
    sys schema
   </a>
   to monitor
          MySQL memory usage.
  </p>
  <p>
   Most Performance Schema memory instrumentation is disabled by
          default. Instruments can be enabled by updating the
   <code class="literal">
    ENABLED
   </code>
   column of the Performance Schema
   <a class="link" href="performance-schema-setup-instruments-table.html" title="29.12.2.3 The setup_instruments Table">
    <code class="literal">
     setup_instruments
    </code>
   </a>
   table. Memory
          instruments have names in the form of
   <code class="literal">
    memory/
    <em class="replaceable">
     <code>
      code_area
     </code>
    </em>
    /
    <em class="replaceable">
     <code>
      instrument_name
     </code>
    </em>
   </code>
   ,
          where
   <em class="replaceable">
    <code>
     code_area
    </code>
   </em>
   is a value such as
   <code class="literal">
    sql
   </code>
   or
   <code class="literal">
    innodb
   </code>
   , and
   <em class="replaceable">
    <code>
     instrument_name
    </code>
   </em>
   is the instrument
          detail.
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      To view available MySQL memory instruments, query the
              Performance Schema
      <a class="link" href="performance-schema-setup-instruments-table.html" title="29.12.2.3 The setup_instruments Table">
       <code class="literal">
        setup_instruments
       </code>
      </a>
      table. The
              following query returns hundreds of memory instruments for
              all code areas.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa26417549"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>setup_instruments
       <span class="token keyword">WHERE</span> <span class="token keyword">NAME</span> <span class="token operator">LIKE</span> <span class="token string">'%memory%'</span><span class="token punctuation">;</span></code></pre>
     </div>
     <p>
      You can narrow results by specifying a code area. For
              example, you can limit results to
      <code class="literal">
       InnoDB
      </code>
      memory instruments by specifying
      <code class="literal">
       innodb
      </code>
      as the code area.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa17360194"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>setup_instruments
       <span class="token keyword">WHERE</span> <span class="token keyword">NAME</span> <span class="token operator">LIKE</span> <span class="token string">'%memory/innodb%'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> NAME                                      <span class="token punctuation">|</span> ENABLED <span class="token punctuation">|</span> TIMED <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/adaptive hash index         <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/buf_buf_pool                <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/dict_stats_bg_recalc_pool_t <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/dict_stats_index_map_t      <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/dict_stats_n_diff_on_level  <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/other                       <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/row_log_buf                 <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/row_merge_sort              <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/std                         <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/trx_sys_t::rw_trx_ids       <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
     </div>
     <p>
      Depending on your MySQL installation, code areas may
              include
      <code class="literal">
       performance_schema
      </code>
      ,
      <code class="literal">
       sql
      </code>
      ,
      <code class="literal">
       client
      </code>
      ,
      <code class="literal">
       innodb
      </code>
      ,
      <code class="literal">
       myisam
      </code>
      ,
      <code class="literal">
       csv
      </code>
      ,
      <code class="literal">
       memory
      </code>
      ,
      <code class="literal">
       blackhole
      </code>
      ,
      <code class="literal">
       archive
      </code>
      ,
      <code class="literal">
       partition
      </code>
      , and others.
     </p>
    </li>
    <li class="listitem">
     <p>
      To enable memory instruments, add a
      <code class="literal">
       performance-schema-instrument
      </code>
      rule to
              your MySQL configuration file. For example, to enable all
              memory instruments, add this rule to your configuration
              file and restart the server:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-ini"><div class="docs-select-all right" id="sa25148192"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-ini"><span class="token constant">performance-schema-instrument</span><span class="token attr-value"><span class="token punctuation">=</span>'memory/%=COUNTED'</span></code></pre>
     </div>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       Enabling memory instruments at startup ensures that
                memory allocations that occur at startup are counted.
      </p>
     </div>
     <p>
      After restarting the server, the
      <code class="literal">
       ENABLED
      </code>
      column of the Performance
              Schema
      <a class="link" href="performance-schema-setup-instruments-table.html" title="29.12.2.3 The setup_instruments Table">
       <code class="literal">
        setup_instruments
       </code>
      </a>
      table should report
      <code class="literal">
       YES
      </code>
      for memory
              instruments that you enabled. The
      <code class="literal">
       TIMED
      </code>
      column in the
      <a class="link" href="performance-schema-setup-instruments-table.html" title="29.12.2.3 The setup_instruments Table">
       <code class="literal">
        setup_instruments
       </code>
      </a>
      table is
              ignored for memory instruments because memory operations
              are not timed.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa7318312"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>setup_instruments
       <span class="token keyword">WHERE</span> <span class="token keyword">NAME</span> <span class="token operator">LIKE</span> <span class="token string">'%memory/innodb%'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> NAME                                      <span class="token punctuation">|</span> ENABLED <span class="token punctuation">|</span> TIMED <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/adaptive hash index         <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/buf_buf_pool                <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/dict_stats_bg_recalc_pool_t <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/dict_stats_index_map_t      <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/dict_stats_n_diff_on_level  <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/other                       <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/row_log_buf                 <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/row_merge_sort              <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/std                         <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb/trx_sys_t::rw_trx_ids       <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span> NO    <span class="token punctuation">|</span></span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      Query memory instrument data. In this example, memory
              instrument data is queried in the Performance Schema
      <a class="link" href="performance-schema-memory-summary-tables.html" title="29.12.20.10 Memory Summary Tables">
       <code class="literal">
        memory_summary_global_by_event_name
       </code>
      </a>
      table, which summarizes data by
      <code class="literal">
       EVENT_NAME
      </code>
      . The
      <code class="literal">
       EVENT_NAME
      </code>
      is the name of the
              instrument.
     </p>
     <p>
      The following query returns memory data for the
      <code class="literal">
       InnoDB
      </code>
      buffer pool. For column
              descriptions, see
      <a class="xref" href="performance-schema-memory-summary-tables.html" title="29.12.20.10 Memory Summary Tables">
       Section 29.12.20.10, “Memory Summary Tables”
      </a>
      .
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa63781750"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>memory_summary_global_by_event_name
       <span class="token keyword">WHERE</span> EVENT_NAME <span class="token operator">LIKE</span> <span class="token string">'memory/innodb/buf_buf_pool'</span>\G
                  EVENT_NAME: <span class="token keyword">memory</span><span class="token operator">/</span>innodb<span class="token operator">/</span>buf_buf_pool
                 COUNT_ALLOC: <span class="token number">1</span>
                  COUNT_FREE: <span class="token number">0</span>
   SUM_NUMBER_OF_BYTES_ALLOC: <span class="token number">137428992</span>
    SUM_NUMBER_OF_BYTES_FREE: <span class="token number">0</span>
              LOW_COUNT_USED: <span class="token number">0</span>
          CURRENT_COUNT_USED: <span class="token number">1</span>
             HIGH_COUNT_USED: <span class="token number">1</span>
    LOW_NUMBER_OF_BYTES_USED: <span class="token number">0</span>
CURRENT_NUMBER_OF_BYTES_USED: <span class="token number">137428992</span>
   HIGH_NUMBER_OF_BYTES_USED: <span class="token number">137428992</span></code></pre>
     </div>
     <p>
      The same underlying data can be queried using the
      <a class="link" href="sys-schema.html" title="Chapter 30 MySQL sys Schema">
       <code class="literal">
        sys
       </code>
      </a>
      schema
      <a class="link" href="sys-memory-global-by-current-bytes.html" title="30.4.3.19 The memory_global_by_current_bytes and x$memory_global_by_current_bytes Views">
       <code class="literal">
        memory_global_by_current_bytes
       </code>
      </a>
      table, which shows current memory usage within the server
              globally, broken down by allocation type.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa11398658"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> sys<span class="token punctuation">.</span>memory_global_by_current_bytes
       <span class="token keyword">WHERE</span> event_name <span class="token operator">LIKE</span> <span class="token string">'memory/innodb/buf_buf_pool'</span>\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
       event_name<span class="token punctuation">:</span> memory/innodb/buf_buf_pool
    current_count<span class="token punctuation">:</span> 1
    current_alloc<span class="token punctuation">:</span> 131.06 MiB
current_avg_alloc<span class="token punctuation">:</span> 131.06 MiB
       high_count<span class="token punctuation">:</span> 1
       high_alloc<span class="token punctuation">:</span> 131.06 MiB
   high_avg_alloc<span class="token punctuation">:</span> 131.06 MiB</span></code></pre>
     </div>
     <p>
      This
      <a class="link" href="sys-schema.html" title="Chapter 30 MySQL sys Schema">
       <code class="literal">
        sys
       </code>
      </a>
      schema query
              aggregates currently allocated memory
              (
      <code class="literal">
       current_alloc
      </code>
      ) by code area:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa43500648"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">SUBSTRING_INDEX</span><span class="token punctuation">(</span>event_name<span class="token punctuation">,</span><span class="token string">'/'</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span> <span class="token keyword">AS</span>
       code_area<span class="token punctuation">,</span> FORMAT_BYTES<span class="token punctuation">(</span><span class="token function">SUM</span><span class="token punctuation">(</span>current_alloc<span class="token punctuation">)</span><span class="token punctuation">)</span>
       <span class="token keyword">AS</span> current_alloc
       <span class="token keyword">FROM</span> sys<span class="token punctuation">.</span>x$memory_global_by_current_bytes
       <span class="token keyword">GROUP</span> <span class="token keyword">BY</span> <span class="token function">SUBSTRING_INDEX</span><span class="token punctuation">(</span>event_name<span class="token punctuation">,</span><span class="token string">'/'</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span>
       <span class="token keyword">ORDER</span> <span class="token keyword">BY</span> <span class="token function">SUM</span><span class="token punctuation">(</span>current_alloc<span class="token punctuation">)</span> <span class="token keyword">DESC</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> code_area                 <span class="token punctuation">|</span> current_alloc <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/innodb             <span class="token punctuation">|</span> 843.24 MiB    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/performance_schema <span class="token punctuation">|</span> 81.29 MiB     <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/mysys              <span class="token punctuation">|</span> 8.20 MiB      <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/sql                <span class="token punctuation">|</span> 2.47 MiB      <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/memory             <span class="token punctuation">|</span> 174.01 KiB    <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/myisam             <span class="token punctuation">|</span> 46.53 KiB     <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/blackhole          <span class="token punctuation">|</span> 512 bytes     <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/federated          <span class="token punctuation">|</span> 512 bytes     <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/csv                <span class="token punctuation">|</span> 512 bytes     <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> memory/vio                <span class="token punctuation">|</span> 496 bytes     <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
     </div>
     <p>
      For more information about
      <a class="link" href="sys-schema.html" title="Chapter 30 MySQL sys Schema">
       <code class="literal">
        sys
       </code>
      </a>
      schema, see
      <a class="xref" href="sys-schema.html" title="Chapter 30 MySQL sys Schema">
       Chapter 30,
       <i>
        MySQL sys Schema
       </i>
      </a>
      .
     </p>
    </li>
   </ol>
  </div>
 </div>
 <br/>
</div>
