The MySQL server's disk is almost full. What do you check and clean?
IntermediateTroubleshootingMySQL
Answer
Short answer
Find what is using the space: usually binary logs, data growth in one table, slow/general logs, or temporary files from big queries. Clean safely (purge old binlogs, rotate logs), then fix the cause (binlog retention, data archiving, more storage or storage autoscaling).
Investigate
df -h /var/lib/mysql
sudo du -sh /var/lib/mysql/* | sort -h | tail
SHOW BINARY LOGS; -- total binlog size
SELECT table_schema, table_name,
ROUND((data_length + index_length)/1024/1024/1024, 2) AS gb
FROM information_schema.tables ORDER BY gb DESC LIMIT 10;
SHOW VARIABLES LIKE 'general_log%'; -- general log left ON?
Safe clean-up
PURGE BINARY LOGS BEFORE NOW() - INTERVAL 2 DAY; -- make sure replicas don't still need them!
SET GLOBAL binlog_expire_logs_seconds = 259200; -- keep 3 days going forward
SET GLOBAL general_log = 'OFF';
Never delete binlog files with rm — MySQL's index file goes out of sync.
Long-term
- Archive or partition old data;
OPTIMIZE TABLEafter big deletes (locks/rebuilds — schedule it). - RDS: enable storage autoscaling; alert at 80% (
FreeStorageSpace).
What to say in the interview
"I find the space hog with du and information_schema: binlogs, a big table, general or slow logs. I purge binlogs with PURGE BINARY LOGS after checking replicas, set retention, turn off the general log, and then archive data or enable storage autoscaling with alerts."
More on MySQL
How do you set up MySQL and log in to it?BeginnerHow do you create a database, a table and see data in MySQL?BeginnerHow do you create a MySQL user for an application and give it permissions?BeginnerHow do you back up and restore a MySQL database?BeginnerWhat is a relational database?BeginnerWhat is the difference between a database, a table, a row and a column?Beginner