{"id":154,"date":"2025-10-21T08:11:31","date_gmt":"2025-10-21T00:11:31","guid":{"rendered":"https:\/\/www.sretalk.com\/?p=154"},"modified":"2025-10-21T08:11:32","modified_gmt":"2025-10-21T00:11:32","slug":"mysql-%e5%b7%a1%e6%a3%80%e5%91%bd%e4%bb%a4%ef%bc%88%e7%a4%ba%e4%be%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.sretalk.com\/?p=154","title":{"rendered":"MySQL \u5de1\u68c0\u547d\u4ee4\uff08\u793a\u4f8b\uff09"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\u4e00\u3001\u57fa\u672c\u4fe1\u606f\u4e0e\u7248\u672c<\/h1>\n\n\n\n<pre class=\"wp-block-code language=bash\"><code># MySQL \u7248\u672c\nmysql -e \"SELECT VERSION();\"\n\n# \u542f\u52a8\u65f6\u95f4\u4e0e\u8fd0\u884c\u65f6\u957f\nmysql -e \"SHOW GLOBAL STATUS LIKE 'Uptime';\"\n\n# \u4e3b\u673a\u540d\u4e0e\u7aef\u53e3\nmysql -e \"SHOW VARIABLES WHERE Variable_name IN ('hostname', 'port');\"\n\n# \u6570\u636e\u76ee\u5f55\u4e0e\u914d\u7f6e\u6587\u4ef6\nmysql -e \"SHOW VARIABLES LIKE 'datadir';\"\nmysql -e \"SHOW VARIABLES LIKE 'pid_file';\"\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e8c\u3001\u7cfb\u7edf\u4e0e\u7f16\u8bd1\u53c2\u6570<\/h1>\n\n\n\n<pre class=\"wp-block-code language=bash\"><code># \u67e5\u770b\u7cfb\u7edf\u53c2\u6570\uff08\u90e8\u5206\uff09\nmysql -e \"SHOW VARIABLES LIKE '%buffer%';\"\nmysql -e \"SHOW VARIABLES LIKE '%cache%';\"\nmysql -e \"SHOW VARIABLES LIKE '%timeout%';\"\n\n# \u7ebf\u7a0b\u5e76\u53d1\u76f8\u5173\u53c2\u6570\nmysql -e \"SHOW VARIABLES LIKE '%thread%';\"\n\n# \u5b57\u7b26\u96c6\u4e0e\u65f6\u533a\nmysql -e \"SHOW VARIABLES LIKE 'character_set_%';\"\nmysql -e \"SHOW VARIABLES LIKE 'collation_%';\"\nmysql -e \"SHOW VARIABLES LIKE 'time_zone';\"\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e09\u3001\u5b9e\u4f8b\u8fd0\u884c\u72b6\u6001\u4e0e\u6027\u80fd\u6307\u6807<\/h1>\n\n\n\n<pre class=\"wp-block-code language=bash\"><code># \u7ebf\u7a0b\u8fde\u63a5\u6570\nmysql -e \"SHOW GLOBAL STATUS LIKE 'Threads_connected';\"\nmysql -e \"SHOW GLOBAL STATUS LIKE 'Threads_running';\"\n\n# QPS\/TPS\nmysql -e \"SHOW GLOBAL STATUS WHERE Variable_name IN ('Questions', 'Com_commit', 'Com_rollback');\"\n\n# \u7f13\u51b2\u6c60\u547d\u4e2d\u7387\uff08InnoDB\uff09\nmysql -e \"SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool%';\"\n\n# \u7f13\u5b58\u547d\u4e2d\u7387\nmysql -e \"SHOW GLOBAL STATUS LIKE 'Qcache%';\"\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u56db\u3001\u8fde\u63a5\u4e0e\u4f1a\u8bdd\u72b6\u6001<\/h1>\n\n\n\n<pre class=\"wp-block-code language=bash\"><code># \u5f53\u524d\u8fde\u63a5\u4f1a\u8bdd\nmysql -e \"SHOW PROCESSLIST;\"\n\n# \u6d3b\u8dc3\u8fde\u63a5\u7edf\u8ba1\nmysql -e \"SELECT USER,HOST,COMMAND,STATE,TIME FROM information_schema.PROCESSLIST WHERE COMMAND!='Sleep';\"\n\n# \u6700\u5927\u8fde\u63a5\u6570\nmysql -e \"SHOW VARIABLES LIKE 'max_connections';\"\nmysql -e \"SHOW GLOBAL STATUS LIKE 'Max_used_connections';\"\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e94\u3001\u9501\u4e0e\u4e8b\u52a1<\/h1>\n\n\n\n<pre class=\"wp-block-code language=bash\"><code># \u5f53\u524d\u9501\u7b49\u5f85\nmysql -e \"SELECT * FROM information_schema.INNODB_LOCKS\\G\"\nmysql -e \"SELECT * FROM information_schema.INNODB_LOCK_WAITS\\G\"\n\n# \u6d3b\u52a8\u4e8b\u52a1\nmysql -e \"SELECT * FROM information_schema.INNODB_TRX\\G\"\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u516d\u3001\u6162\u67e5\u8be2\u4e0e\u65e5\u5fd7<\/h1>\n\n\n\n<pre class=\"wp-block-code language=bash\"><code># \u6162\u67e5\u8be2\u662f\u5426\u542f\u7528\nmysql -e \"SHOW VARIABLES LIKE 'slow_query_log';\"\nmysql -e \"SHOW VARIABLES LIKE 'slow_query_log_file';\"\n\n# \u6162\u67e5\u8be2\u7edf\u8ba1\nmysql -e \"SHOW GLOBAL STATUS LIKE 'Slow_queries';\"\n\n# \u67e5\u770b\u9519\u8bef\u65e5\u5fd7\u8def\u5f84\nmysql -e \"SHOW VARIABLES LIKE 'log_error';\"\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e03\u3001InnoDB \u5b58\u50a8\u5f15\u64ce\u72b6\u6001<\/h1>\n\n\n\n<pre class=\"wp-block-code language=bash\"><code>mysql -e \"SHOW ENGINE INNODB STATUS\\G\"\nmysql -e \"SHOW ENGINE INNODB MUTEX\\G\"\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u516b\u3001\u6570\u636e\u5e93\u4e0e\u8868\u7a7a\u95f4\u4fe1\u606f<\/h1>\n\n\n\n<pre class=\"wp-block-code language=bash\"><code># \u6570\u636e\u5e93\u5927\u5c0f\nmysql -e \"SELECT table_schema AS 'Database',\n       ROUND(SUM(data_length+index_length)\/1024\/1024,2) AS 'Size_MB'\nFROM information_schema.tables\nGROUP BY table_schema ORDER BY Size_MB DESC;\"\n\n# \u8868\u6570\u91cf\u53ca\u5927\u5c0f\nmysql -e \"SELECT table_schema, COUNT(*) AS tables,\n       ROUND(SUM(data_length+index_length)\/1024\/1024,2) AS size_mb\nFROM information_schema.tables\nGROUP BY table_schema ORDER BY size_mb DESC;\"\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e5d\u3001\u4e3b\u4ece\u590d\u5236\u72b6\u6001\uff08\u5982\u679c\u6709\uff09<\/h1>\n\n\n\n<pre class=\"wp-block-code language=bash\"><code># \u4e3b\u5e93\nmysql -e \"SHOW MASTER STATUS\\G\"\n\n# \u4ece\u5e93\nmysql -e \"SHOW SLAVE STATUS\\G\"\n\n# \u590d\u5236\u5ef6\u8fdf\nmysql -e \"SHOW SLAVE STATUS\\G\" | grep -E \"Seconds_Behind_Master|Slave_IO_Running|Slave_SQL_Running\"\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u5341\u3001\u64cd\u4f5c\u7cfb\u7edf\u5c42\u9762\uff08\u53ef\u9009\uff09<\/h1>\n\n\n\n<pre class=\"wp-block-code language=bash\"><code># \u7cfb\u7edf\u7248\u672c\ncat \/etc\/os-release | grep PRETTY_NAME\n\n# MySQL \u670d\u52a1\u72b6\u6001\nsystemctl status mysqld | head -n 10\n\n# \u5185\u5b58\u4e0eCPU\u4f7f\u7528\u60c5\u51b5\ntop -bn1 | grep mysqld\nps -eo pid,pcpu,pmem,etime,cmd | grep mysqld\n\n# \u78c1\u76d8\u4f7f\u7528\ndf -h | grep mysql\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u57fa\u672c\u4fe1\u606f\u4e0e\u7248\u672c \u4e8c\u3001\u7cfb\u7edf\u4e0e\u7f16\u8bd1\u53c2\u6570 \u4e09\u3001\u5b9e\u4f8b\u8fd0\u884c\u72b6\u6001\u4e0e\u6027\u80fd\u6307\u6807 \u56db\u3001\u8fde\u63a5\u4e0e\u4f1a\u8bdd\u72b6\u6001 \u4e94\u3001\u9501\u4e0e\u4e8b\u52a1 \u516d\u3001\u6162\u67e5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-154","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.sretalk.com\/index.php?rest_route=\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sretalk.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sretalk.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sretalk.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sretalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=154"}],"version-history":[{"count":1,"href":"https:\/\/www.sretalk.com\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":155,"href":"https:\/\/www.sretalk.com\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions\/155"}],"wp:attachment":[{"href":"https:\/\/www.sretalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sretalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sretalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}