- Enable the slow query log if it's not already enabled:SET GLOBAL slowquerylog = 'ON';
     SET GLOBAL longquerytime = 2; -- Adjust based on need, captures queries taking longer than 2 seconds.
     SET GLOBAL slowquerylog_file = '/path/to/your/logfile.log';
   - Analyze the log file using tools like `mysqldumpslow` or `pt-query-digest` to find the most resource-intensive queries.
SELECT tableschema AS `Database`, tablename AS `Table`, 
   round(((datalength + indexlength) / 1024 / 1024), 2) `Size in MB` 
   FROM information_schema.TABLES 
   ORDER BY (datalength + indexlength) DESC;
   - Use the `EXPLAIN` statement on slow queries to check if indexes are being used effectively.
   - Investigate columns used in JOIN, WHERE, ORDER BY, and GROUP BY clauses for potential indexing.
   - Query performance schema or information_schema to analyze memory allocation:SELECT * FROM sys.x$memoryglobalbycurrentbytes WHERE currentcount > 0 ORDER BY currentallocated DESC;
   - Adjust key buffer sizes if necessary, for example:SET GLOBAL keybuffersize = 268435456; -- Adjust size according to analysis
   - Check max connections:SHOW VARIABLES LIKE "max_connections";
   - Adjust if necessary:SET GLOBAL max_connections = 200; -- Adjust based on your server’s capability and needs.
   - Check current buffer pool size:SHOW VARIABLES LIKE 'innodbbufferpool_size';
   - Adjust the buffer pool size (example):SET GLOBAL innodbbufferpool_size = 134217728; -- Adjust based on system RAM and MySQL documentation.
OPTIMIZE TABLE yourtablename;
10. Finally, if specific queries are identified as problematic, consider rewriting them for efficiency or implementing caching mechanisms to reduce database load.
(Perfect for DevOps & SREs)
(Perfect for DevOps & SREs)



