{"id":3098,"date":"2023-12-11T14:20:42","date_gmt":"2023-12-11T14:20:42","guid":{"rendered":"https:\/\/kedar.nitty-witty.com\/blog\/?p=3098"},"modified":"2024-01-27T17:21:57","modified_gmt":"2024-01-27T17:21:57","slug":"what-do-you-need-to-debug-mysql-issues-a-checklist","status":"publish","type":"post","link":"https:\/\/kedar.nitty-witty.com\/blog\/what-do-you-need-to-debug-mysql-issues-a-checklist","title":{"rendered":"What do you need to debug MySQL issues &#8211; a checklist"},"content":{"rendered":"\n<p>Welcome to the ultimate guide for MySQL issues debugging \u2014 your comprehensive MySQL checklist for tackling MySQL database environment challenges. This checklist for MySQL debugging is as useful to a MySQL database consultant as it is for someone seeking remote support. <\/p>\n\n\n\n<p>This MySQL Debugging Checklist, outlines steps and tasks crucial for identifying and resolving MySQL issues. It aims to provide you with the guideline of what-to-look-for and where without missing points. <\/p>\n\n\n\n<p>This checklist is not only beneficial for MySQL database consultants but also for those seeking remote support should be able to provide the checklist information to the consultants to provide their inputs.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">MySQL checklist for debugging issues<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li>MySQL configuration and status<\/li>\n\n\n\n<li>MySQL processlist<\/li>\n\n\n\n<li>Reviewing MySQL ENGINE InnoDB STATUS<\/li>\n\n\n\n<li>MySQL error log<\/li>\n\n\n\n<li>Slow query log<\/li>\n\n\n\n<li>System statuses<\/li>\n\n\n\n<li>Monitoring and observability tools<\/li>\n\n\n\n<li>Kernel log review<\/li>\n\n\n\n<li>MySQL&#8217;s binary log analysis<\/li>\n\n\n\n<li>Recent changes on the system<\/li>\n<\/ul>\n\n\n\n<p>Consider using the list to provide assistance to debug and resolve the MySQL issues, not necessarily in the exact order. The list here is not exhaustive and may need further points to consider for resolving the possible performance or stability issue in MySQL.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">MySQL Checklist details<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL configuration and status<\/h2>\n\n\n\n<p>Checking the MySQL status and uptime provides an overview of the server&#8217;s health and availability.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Sample Command: \nmysql&gt; status<\/code><\/pre>\n\n\n\n<p>The &#8220;status&#8221; command will provide you with the uptime with additional information. This is where you can also find the MYSQL version which is important to understand what are you dealing with \ud83d\ude42<\/p>\n\n\n\n<p>Usually, MySQL configuration variables and statuses can be collected in a file as noted below and can provide additional information:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -e \"show global variables;\" &gt; variables<br>mysql -e \"show global status;\" &gt; status<\/code><\/pre>\n\n\n\n<p>pt-mysql-summary &#8211; is the tool that can also help you collecting and identifying the MySQL statuses and variables in well formatted output.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL processlist<\/h2>\n\n\n\n<p>MySQL processlist indicates the operations currently being performed by the set of threads executing within the server. A MySQL consultant would like to analyze the MySQL process list in order to identify slow or stuck queries that might be affecting overall performance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Command\nSHOW FULL PROCESSLIST;<\/code><\/pre>\n\n\n\n<p>You may want to get fancy with the &#8220;grep&#8221; &#8211; some of the following commands will help you get an analysis from processlist.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Ignore all the Sleeping connections\npager grep -v Sleep; show full processlist;nopager;\n\n# Command-wise counts\nselect command, count(1) from information_schema.processlist group by command;\n\n# Queries count being executed per query text:\nselect substring(INFO,1,100) query, count(1) from information_schema.processlist group by substring(INFO,1,100);\n\n# Queries count being executed per host:\nselect substring_index(host,':',1), count(1) from information_schema.processlist group by substring_index(host,':',1);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Reviewing MySQL ENGINE InnoDB STATUS<\/h2>\n\n\n\n<p>The Engine InnoDB Status displays extensive information from the standard InnoDB Monitor about the state of the InnoDB storage engine. Examining the InnoDB status reveals valuable information to the MySQL database consultant about transactions, locks, deadlocks, semaphores, history list length, and many other InnoDB engine statuses.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SHOW ENGINE INNODB STATUS\\G<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL error log<\/h2>\n\n\n\n<p>The MySQL error log provides the diagnostic messages such as errors, warnings, and notes that occur during regular operations. It is a usual place for MySQL consultants to look for while debugging an issue. Reviewing error log helps MySQL database consultant by assisting in identifying critical errors \/ warnings or notes possibly that may relate to the ongoing performance or stability issue.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt; select @@log_error # Identify MySQL\u2019s error log<\/code><\/pre>\n\n\n\n<p>If the server is unable to start, you can get the path from the config file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$] grep -i error \/etc\/my.cnf\n$] sudo tail -100 \/var\/log\/mysql\/error.log<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Slow query log<\/h2>\n\n\n\n<p>Enabling the slow query log allows identification of queries that take longer to execute, helping optimize performance.<\/p>\n\n\n\n<p>Sample Command to enable slow query log:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SET GLOBAL slow_query_log = 'ON';\nSET GLOBAL long_query_time = 0; # Collect all the queries<\/code><\/pre>\n\n\n\n<p><strong>The Query Digest to debug query performance<\/strong><\/p>\n\n\n\n<p>pt-query-digest tool is used to analyze MySQL queries from logs(slow \/ general \/ binary), processlist, and tcpdump. When executed on a MySQL slow query log, it generates a detailed output, summarizing key metrics. The output includes an overview of the total number of queries, the percentage of slow queries, and a breakdown of query types. It identifies query classes based on fingerprints, offers examples of slow queries, and provides insights into query sources. Additional sections cover query profiles over time, response time distribution, percentiles, and lock time analysis. The tool&#8217;s output assists database administrators in identifying performance bottlenecks, understanding query patterns, and optimizing overall MySQL database performance.<\/p>\n\n\n\n<p><strong>Data to analyze Slow queries, Table definition, indexes, table size \/ status<\/strong><\/p>\n\n\n\n<p>A MySQL database consultant will require an explain plan, table definitions, and indexes to help identify potential optimization in the slow query. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Query explain plan: \nEXPLAIN &lt;query&gt;;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># Table Definition: \nSHOW CREATE TABLE table_name\\G<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># Indexes: \nSHOW INDEXES FROM table_name\\G<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># Table Size\/Status: \nSHOW TABLE STATUS LIKE 'table_name'\\G<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Monitoring and observability tool&nbsp;<\/h2>\n\n\n\n<p>Utilising monitoring tools like Percona&#8217;s PMM, Prometheus, DataDog or other alternatives ensures real-time performance monitoring, allowing administrators gain valuable visual insights into the database&#8217;s behaviour. <\/p>\n\n\n\n<p>This visual representation is instrumental in pinpointing performance bottlenecks, understanding query or traffic patterns, and making informed decisions to optimize MySQL database performance. Depending on the configuration, you can also see some historical data to gather more insights about the database behaviour.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">System statuses<\/h2>\n\n\n\n<p>Monitoring system metrics like uptime, disk usage, memory, and CPU provides insights into resource bottlenecks and helps identify potential hardware-related problems. Of course the same metrics can also be observed through the monitoring tools like PMM.<\/p>\n\n\n\n<p>Some of the commands on Linux OS should be useful to collect necessary information:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> &nbsp;uptime\n&nbsp;&nbsp;df -h\n&nbsp;&nbsp;free -h\n&nbsp;&nbsp;top\n&nbsp;&nbsp;sar\n&nbsp;&nbsp;vmstat\n&nbsp;&nbsp;iostat&nbsp;<\/code><\/pre>\n\n\n\n<p>The Percona tool, pt-summary will help summarising system information nicely and should also come in handy to the database consultants to review.<\/p>\n\n\n\n<p>Additionally, I&#8217;d also mention Percona Toolkit&#8217;s pt-stalk. The tool, pt-stalk, can be run directly or configured to execute when a trigger condition occurs, then it collects data to help diagnose problems. The diagnostics data are stored in a file which can help consultants by providing additional information along with timestamps.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Kernel log review<\/h2>\n\n\n\n<p>Analyzing the kernel log helps identify system-level issues, such as hardware failures or kernel panics, OoM kills, which could impact MySQL&#8217;s stability. You may check system messages:<\/p>\n\n\n\n<p>Sample Commands and files required to review Kernel logs<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dmesg\n\/var\/log\/messages\n\/var\/log\/syslog<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL&#8217;s binary log analysis<\/h2>\n\n\n\n<p>Analyzing the binary log helps track executed commands, assisting in identifying issues related to data changes or replication.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysqlbinlog --no-defaults --base64-output=decode-rows -vvv &lt;BINLOG_FILE&gt; &gt; binlog.debug<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Recent changes on the system<\/h2>\n\n\n\n<p>At times the MySQL issue can also be related to the recent changes, upgrades or additions on the packages. Checking for recent system changes, like software upgrades or application updates, helps pinpoint the source of issues.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># rhel \/ centos\nsudo yum history list\nsudo yum history info &lt;transaction_id&gt;\n\n# debian based\nless \/var\/log\/apt\/history.log\nless \/var\/log\/dpkg.log<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Having a MySQL debugging checklist information readily available is invaluable when  tackling MySQL issue or seeking assistance from a database consultant. It provides the database consultant with essential details, enabling a quicker and more accurate identification of potential MySQL problems. <\/p>\n","protected":false},"excerpt":{"rendered":"Welcome to the ultimate guide for MySQL issues debugging \u2014 your comprehensive MySQL checklist for tackling MySQL database environment challenges. This checklist for MySQL debugging is as useful to a&hellip;\n","protected":false},"author":1,"featured_media":3100,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[869,8,377],"tags":[427,811,815,816,813,814,812,817],"class_list":{"0":"post-3098","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-mariadb","8":"category-mysql","9":"category-mysql-articles","10":"tag-mysql","11":"tag-mysql-checklist","12":"tag-mysql-consultants","13":"tag-mysql-database-debugging","14":"tag-mysql-debugging-checklist","15":"tag-mysql-issues-checklist","16":"tag-mysql-performance-checklist","17":"tag-mysql-support"},"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/3098","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/comments?post=3098"}],"version-history":[{"count":8,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/3098\/revisions"}],"predecessor-version":[{"id":3107,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/3098\/revisions\/3107"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media\/3100"}],"wp:attachment":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media?parent=3098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/categories?post=3098"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/tags?post=3098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}