1. 程式人生 > >mysql日常檢查

mysql日常檢查

justify mysql style

1) 進入mysql終端

# mysql -uroot -p

2) 查看版本

# mysqladmin -uroot -p version

select @@version;

3) 列出數據庫

show databases;

4) 顯示哪些線程正在運行

show processlist

5) 查看配置

# cat /etc/my.cnf

6) 查看引擎

>show engines;

默認的引擎

show variables like ‘%storage_engine%‘;

7) 查詢日誌

show variables like ‘log_%‘;

# cat /etc/my.cnf |grep log

log-bin=mysql-bin

binlog_format=mixed

log-error=/var/log/mysqld.log

# tail -n 20 /var/log/mysqld.log

8) 查看所有庫大小

 select concat(round(sum(DATA_LENGTH/1024/1024)+sum(INDEX_LENGTH/1024/1024), 2), ‘MB‘) as data from information_schema.tables

所有庫大小

select TABLE_SCHEMA, concat(truncate
(sum(data_length)/1024/1024,2),‘ MB‘) as data_size,concat(truncate(sum(index_length)/1024/1024,2),‘MB‘) as index_size from information_schema.tables group by TABLE_SCHEMA order by data_length desc
;

指定庫所有表大小

select TABLE_NAME, concat(truncate(data_length/1024,2),‘ KB‘) as data_size, concat(truncate(index_length/1024,2),‘ KB‘) as index_size from information_schema.tables where TABLE_SCHEMA = ‘mysql‘ group by TABLE_NAME order by data_length desc;

9) 查詢表鎖統計

show status like ‘table%‘;

如果waited數值較高,說明鎖爭用較嚴重

10) 檢查鍵效率

show status like ‘key_read%‘;

key_reads/key_read_requests 盡可能低,至少是1:100,最好是1:1000

11) 檢查請求緩存命中

show status like ‘Qcache%‘;

Qcache_lowmem_prunes值非常大,說明緩沖不夠

Qcache_hits非常大,說明查詢緩沖使用非常頻繁,需增大緩沖

12) 判斷是否主從

show global status like ‘Slave_running‘;

13) 臨時表

show status like ‘%tmp%‘;

正常created_tmp_disk_tables/created_tmp_tables*100%<=25%

mysql日常檢查