MySQL Full Disk/Storage Issues

Running out of disk space due to large logs, binary logs, or unoptimized data storage, leading to service disruptions.
  1. Check and Free Up Space:


- Identify and delete any unnecessary files or logs in the server to quickly free up space.
cd /var/log/mysql
sudo rm -rf your-unneeded-log-files.log


  1. Identify Large Tables:


- Use this query to find large tables that might be candidates for cleanup or pruning.
SELECT tableschema AS `Database`, tablename AS `Table`,
round(((data
length + indexlength) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
ORDER BY (data
length + indexlength) DESC;

  1. Cleanup Binary Logs:


- If binary logging is enabled and you don't need the old logs, you can purge them.
PURGE BINARY LOGS BEFORE '2023-01-01 00:00:00';

  1. Optimize/Prune Large Tables:


- Based on the previous step, decide if you can delete old or unnecessary data from large tables.
DELETE FROM yourtable WHERE yourdate_column < 'YYYY-MM-DD';
- After cleanup, optimize the table to reclaim space.
OPTIMIZE TABLE your_table;

  1. Compress Tables:


- For InnoDB tables, consider enabling compression for large tables.
ALTER TABLE yourtablename ROW_FORMAT=COMPRESSED;

  1. Increase Disk Space:


- If possible, add more disk space to the server. This might involve contacting your hosting provider or using cloud management tools depending on your environment.

  1. Check and Adjust Log File Size:


- If the InnoDB log files are consuming too much space, consider resizing them. Note: This requires restarting MySQL.
- Check the current size:
SHOW VARIABLES LIKE 'innodblogfile_size';
- To change the size, you'll need to edit the `my.cnf` or `my.ini` file and restart MySQL.

  1. Move Data Directory:


- If you have an additional storage device with more space, move the MySQL data directory to this location.
- Stop MySQL service.
sudo systemctl stop mysql
- Copy the data directory to the new location.
sudo cp -R -p /var/lib/mysql /new/path
- Update the `datadir` in `my.cnf` or `my.ini` with the new path and restart MySQL.

  1. Archive Old Data:


- If there are tables with historical data that are not frequently accessed, consider archiving this data to a separate database or storage.

  1. Check for Duplicate Indexes:


- Duplicate indexes can consume unnecessary space.
SELECT tableschema, tablename, GROUPCONCAT(indexname SEPARATOR ', ') AS indexes
FROM information_schema.statistics
WHERE table
schema NOT IN ('informationschema', 'mysql', 'performance_schema', 'sys')
GROUP BY table
schema, tablename, indextype, columnname
HAVING COUNT(*) > 1;

Never debug

MySQL

manually again

Let Dr. Droid create custom investigation plans for your infrastructure.

Start Free POC (15-min setup) →
Automate Debugging for
MySQL
See how Dr. Droid creates investigation plans for your infrastructure.

MORE ISSUES

Made with ❤️ in Bangalore & San Francisco 🏢

Doctor Droid