您好,登錄后才能下訂單哦!
mysql中的監(jiān)控與優(yōu)化過程是怎樣的,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
mysql> show global status like 'Com%'; mysql> show global status like 'Queries'; +---------------+---------+ | Variable_name | Value | +---------------+---------+ | Queries | 1983766 | +---------------+---------+ 1 row in set (0.00 sec)
QPS = ( Queries 2- Queries 1 ) / 間隔時間
mysql> show global status where variable_name in ('Queries','uptime'); +---------------+---------+ | Variable_name | Value | +---------------+---------+ | Queries | 1983768 | | Uptime | 1364443 | +---------------+---------+ 2 rows in set (0.00 sec)
mysql> show global status where variable_name in ('com_insert','com_update','com_delete','uptime'); +---------------+---------+ | Variable_name | Value | +---------------+---------+ | Com_delete | 23676 | | Com_insert | 793072 | | Com_update | 259586 | | Uptime | 1364651 | +---------------+---------+ 4 rows in set (0.00 sec)
Transaction_sum= Com_delete+ Com_insert+ Com_update
TPS = (Transaction_sum 2 - Transaction_sum 1 ) / (time 2 - time 1)
mysql> show global status like 'Threads_running'; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | Threads_running | 2 | +-----------------+-------+ 1 row in set (0.01 sec)
# 最大連接數(shù) mysql> show global status like 'max_used_connections%'; +---------------------------+---------------------+ | Variable_name | Value | +---------------------------+---------------------+ | Max_used_connections | 22 | | Max_used_connections_time | 2019-09-04 13:49:52 | +---------------------------+---------------------+ 2 rows in set (0.00 sec) # 當(dāng)前連接數(shù) mysql> show global status like 'threads_connected'; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | Threads_connected | 2 | +-------------------+-------+ 1 row in set (0.01 sec)
##從緩存中讀取的次數(shù) mysql> show global status like 'innodb_buffer_pool_read_requests'; +----------------------------------+----------+ | Variable_name | Value | +----------------------------------+----------+ | Innodb_buffer_pool_read_requests | 16217299 | +----------------------------------+----------+ 1 row in set (0.00 sec) ##從物理磁盤讀取的次數(shù) mysql> show global status like 'innodb_buffer_pool_reads'; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | Innodb_buffer_pool_reads | 2067 | +--------------------------+-------+ 1 row in set (0.00 sec)
緩存命中率 = ( innodb_buffer_pool_read_requests - innodb_buffer_pool_reads ) /
innodb_buffer_pool_reads * 100%
周期連接,執(zhí)行查詢:select @ @version; 或 select user();
mysqladmin -uroot -pxxx -hxxxx ping
##< mysql 5.7 SELECT b.trx_mysql_thread_id as '被阻塞的線程', b.trx_query as '被阻塞的SQL', c.trx_mysql_thread_id as '阻塞線程', c.trx_query as '阻塞SQL', UNIX_TIMESTAMP()-UNIX_TIMESTAMP(c.trx_started)) as '阻塞時間' FROM information_schema.INNODB_LOCK_WAITS a JOIN information_schema.INNODB_TRX b ON a.requesting_trx_id=b.trx_id JOIN information_schema.INNODB_TRX c ON a.blocking_trx_id=c.trx_id WHERE (UNIX_TIMESTAMP()-UNIX_TIMESTAMP(c.trx_started))>30 ##> mysql 5.7 SELECT waiting_pid AS '被阻塞的線程', waiting_query AS '被阻塞的SQL', blocking_pid AS '阻塞線程', blocking_query AS '阻塞SQL', wait_age AS '阻塞時間', sql_kill_blocking_query AS '建議操作' FROM sys.innodb_lock_waits WHERE (UNIX_TIMESTAMP()-UNIX_TIMESTAMP(wait_started))>30
##pt工具 pt-deadlock-logger u=admin, p=123456, h=127.0.0.1 \ --create-dest-table \ --dest u=admin,p=123456, h=127.0.0.1.D=dba,t=deadlock ##全局參數(shù),日志監(jiān)控 mysql> set persist innodb_print_all_deadlocks=on;
監(jiān)控慢查詢?nèi)罩?/p>
通過information_shcema.processlist表實時監(jiān)控
show slave status\G
pt-heartbeat
##主庫 pt-heartbeat --user=xx --password=xxx -h master --create-table --database xxx --update --daemonize --interval=1 ##從庫 pt-hearbeat --user=xx --password=xx -h slave --database xxx --monitor --daemonize --log /tmp/slave_lag.log
show slave status\G
IO/SQL 兩個線程狀態(tài)(yes or no)
看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進(jìn)一步的了解或閱讀更多相關(guān)文章,請關(guān)注億速云行業(yè)資訊頻道,感謝您對億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。