Server disk full, Mysql service can't start, how can i shrink the database?
I'm currently having a major issue. VPS disk is full, mysql database grew unexpectedly, and can't buy more space from the hosting because it's already maxed out.
The mysql service can't start anymore because of storage space.
Is there any way I could execute queries on the database with the service off? But I guess it would require some third party tools, and the space on the server doesn't permit that. If I'm not mistaken, even if i delete some old data from the database, it won't shrink anyway.
I can't even download the entire database files on my computer and try to rebuild it there, because it's so huge I don't have any drive where it could fit.
What options I have now? Does anyone have any idea about what i could do next?
MySQL doesn't run as root, so you probably still have 'reserved' free space. You can reclaim that: tune2fs -m 0 /dev/whatever
.
You didn't say what OS you have, but there is probably some space you can free up elsewhere. If you have Ubuntu, try apt clean
. Remove log files from /var/log/*
, etc.
If you still can install something, install ncdu
and do ncdu -x /
to give you an easy overview of what to delete.
Also, a trick I often do, is have a dummy file of a few hundred MBs somewhere, that can be removed if you run into this situation. That, and monitoring of course.
Once you do have space, you're going to have to run OPTIMIZE TABLE
on the offending table. However, this will cause a recreate, so you need extra space for that. Also, it requires running with innodb_file_per_table
, which is the default nowadays.