MySQL中的監(jiān)控與優(yōu)化過(guò)程是怎樣的,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。
專業(yè)從事網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè),高端網(wǎng)站制作設(shè)計(jì),成都小程序開(kāi)發(fā),網(wǎng)站推廣的成都做網(wǎng)站的公司。優(yōu)秀技術(shù)團(tuán)隊(duì)竭力真誠(chéng)服務(wù),采用HTML5+CSS3前端渲染技術(shù),成都響應(yīng)式網(wǎng)站建設(shè)公司,讓網(wǎng)站在手機(jī)、平板、PC、微信下都能呈現(xiàn)。建站過(guò)程建立專項(xiàng)小組,與您實(shí)時(shí)在線互動(dòng),隨時(shí)提供解決方案,暢聊想法和感受。
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 ) / 間隔時(shí)間
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 '阻塞時(shí)間' 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 '阻塞時(shí)間', 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>
通過(guò)information_shcema.processlist表實(shí)時(shí)監(jiān)控
show slave status\G
pt-heartbeat
##主庫(kù) pt-heartbeat --user=xx --password=xxx -h master --create-table --database xxx --update --daemonize --interval=1 ##從庫(kù) pt-hearbeat --user=xx --password=xx -h slave --database xxx --monitor --daemonize --log /tmp/slave_lag.log
show slave status\G
IO/SQL 兩個(gè)線程狀態(tài)(yes or no)
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。