立即學習:https://edu.csdn.net/course/play/10084/221706?utm_source=blogtoedu
MySQL狀態變量
作用:反映當前mysql數據庫服務器自當次啓動以來的累計相關狀態信息,如SQL執行效率,緩存使用情況,鎖資源使用情況。
全局狀態變量(208個)
會話狀態變量(211個)
會話狀態變量爲當前會話對系統資源的使用情況,有些狀態變量無會話級,查看時會顯示系統級狀態變量。
注:狀態變量不可人爲修改,由系統自動修改,mysqld重啓丟失
注:任意狀態變量在未使用global關鍵字時,缺省爲會話級別變量,對於無會話級別變量,無論是否指定global或者session,都顯示爲系統級別變量。
狀態變量查看方法
show方式
show [GLOBAL | SESSION ] STATUS [LIKE 'pattern' |WHERE expr]
系統表
SELECT * FROM global_status | session_status WHERE VARIABLE_NAME LIKE '%pattern%'
mysqladmin extended-status方式
mysqladmin -uroot -pxxx extended-status | grep Connections
從系統表查看
performance_schema.session_status
performance_schema.global_status
重置狀態變量統計信息
flush status;
部分狀態變量可以重置
重置隻影響會話級別,全局級別不受影響
a、查看所有狀態變量
show status;
b、查看僅有global的裝變量(connections)
--查看指定的狀態變量,以下兩個與connections相關的都爲全局狀態變量
--連接到MYSQL服務器的數量(包含成功或失敗的)
show global status like 'connections%';
show global status like '%connections%';
c、查看既有global又有session狀態的變量
--查看session狀態變量opened_tables
show session status like 'opened_tables';
select coun(*) from sakila.customer;
d、查詢系統表獲取狀態變量的值
--從performance_schema.session_status表查詢狀態變量OPENED_TABLES
select * from performance_schema.session_status where variable_name like 'opened_tables';
--查看全局狀態變量opened_tables
select * from performance_schema.global_status where variable_name like 'opened_tables';