MySQL 狀態變數(Server Status Variables)

來源:互聯網
上載者:User

標籤:命令   命令列   session   min   sage   auth   決策   medium   0 rows   

    MySQL狀態變數是當前server自啟動後累計的一些系統狀態資訊,主要用於評估當前系統資源的使用方式以進一步分析系統效能而做出對應的調整決策。這些狀態變數我們能夠理解為等同於Oracle資料庫的動態效能檢視。MySQL的狀態變數有非常多,比方SQL運行頻率。索引的使用方式,鎖資源的使用方式等等。狀態變數能夠分區全域以及會話層級的狀態變數。狀態變數不可改動。為僅僅讀屬性,由系統更新。本文示範了狀態變數的一些示範範例。僅為拋磚引玉之用。

 

1、狀態變數
   反映當前mysql資料庫server自當次啟動以來的累計相關狀態資訊,分為會話級與全域層級狀態資訊。
   與系統變數相似,有些狀態變數有全域和會話層級。而有些僅僅有全域層級。如binlog_cache_disk_use僅有全域狀態,而bytes_sent兩者都有。


   能夠通過show status like ‘%variable_name%‘ 或者show global status like ‘%variable_name%‘來查看。


   在未使用Like的情形下show status會顯示所有的狀態變數。


   能夠通過查詢系統資料表information_schema.global_status以及information_schema.session_status來擷取狀態變數資訊。


   能夠在命令列下通過mysqladmin extended-status方式來擷取狀態變數的相關資訊。


   能夠通過命令列方式mysqladmin extended-status -r -i 5或innotop持續觀察狀態變數的改變情況。


   一些狀態變數重能夠用FLUSH STATUS語句重設為零值。

 

2、show方式查看狀態變數

--當前示範環境[email protected][(none)]> show variables like ‘version‘;+---------------+------------+| Variable_name | Value      |+---------------+------------+| version       | 5.5.39-log |+---------------+------------+a、查看全部狀態變數[email protected][(none)]> show status;+------------------------------------------+-------------+| Variable_name                            | Value       |+------------------------------------------+-------------+| Aborted_clients                          | 0           || Binlog_stmt_cache_use                    | 1           || Bytes_received                           | 135         || Bytes_sent                               | 266         ||               ................           |             | | Threads_running                          | 1           || Uptime                                   | 76242       || Uptime_since_flush_status                | 76242       |+------------------------------------------+-------------+312 rows in set (0.00 sec)   --能夠看出目前的版本號5.5.39有312個狀態變數b、查看僅有global的狀態變數(connections)            --查看指定的狀態變數,下面兩個與connection相關的都為全域狀態變數[email protected][(none)]> show global status like ‘connection%‘;+----------------------+-------+| Variable_name        | Value |+----------------------+-------+| Connections          | 11    | --串連到MySQLserver的數量(包括成功或失敗的)。

+----------------------+-------+suse11b:~ # mysql -ufred[email protected][(none)]> show global status like ‘%connection%‘;+----------------------+-------+| Variable_name | Value |+----------------------+-------+| Connections | 12 | --串連之後。我們看到Connections的值變為12了。+----------------------+-------+c、查看既有global又有session狀態的變數--查看session狀態變數opened_tables[email protected][tempdb]> show session status like ‘opened_tables‘;+---------------+-------+| Variable_name | Value |+---------------+-------+| Opened_tables | 0 |+---------------+-------+[email protected][tempdb]> select count(*) from tb_slow;+----------+| count(*) |+----------+| 424448 |+----------+[email protected][tempdb]> show session status like ‘opened_tables‘;+---------------+-------+| Variable_name | Value |+---------------+-------+| Opened_tables | 1 | --值變為1+---------------+-------+--從information_schema.session_status表查詢狀態變數OPENED_TABLES[email protected][tempdb]> select * from information_schema.session_status -> where variable_name like ‘opened_tables‘;+---------------+----------------+| VARIABLE_NAME | VARIABLE_VALUE |+---------------+----------------+| OPENED_TABLES | 1 |+---------------+----------------+--查看全域狀態變數opened_tables[email protected][tempdb]> show global status like ‘opened_tables‘;+---------------+-------+| Variable_name | Value |+---------------+-------+| Opened_tables | 54 | +---------------+-------+[email protected][tempdb]> select count(*) from mysql.db;+----------+| count(*) |+----------+| 2 |+----------+[email protected][tempdb]> show global status like ‘opened_tables‘;+---------------+-------+| Variable_name | Value |+---------------+-------+| Opened_tables | 55 | --值變為55+---------------+-------+--從information_schema.global_status表查詢狀態變數OPENED_TABLES[email protected][tempdb]> select * from information_schema.global_status -> where variable_name like ‘opened_tables‘;+---------------+----------------+| VARIABLE_NAME | VARIABLE_VALUE |+---------------+----------------+| OPENED_TABLES | 55 | +---------------+----------------+--清洗狀態變數統計資訊[email protected][tempdb]> flush status;Query OK, 0 rows affected (0.00 sec)--以下的查詢結果能夠看出,session層級的opened_tables被重設為0[email protected][tempdb]> show session status like ‘opened_tables‘;+---------------+-------+| Variable_name | Value |+---------------+-------+| Opened_tables | 0 |+---------------+-------+--Author: Leshami--Blog : http://blog.csdn.net/leshami--而全域層級的opened_tables未受到不論什麼影響[email protected][tempdb]> show global status like ‘opened_tables‘;+---------------+-------+| Variable_name | Value |+---------------+-------+| Opened_tables | 55 |+---------------+-------+

3、使用mysqladmin extended-status擷取狀態變數

suse11b:~ # mysqladmin extended-status|grep Connections| Connections                              | 18          |suse11b:~ # mysql[email protected][(none)]> system mysqladmin extended-status|grep Connections| Connections                              | 20          |[email protected][(none)]> exitByesuse11b:~ # mysqladmin --help |more    #mysqladmin與狀態變數有關的使用extended-status       Gives an extended status message from the serverflush-status          Clear status variables

 

MySQL 狀態變數(Server Status Variables)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.