optimize all is the operation that fails. I've noticed that it produces a folder named like the database plus a random number. Maybe I should check whether the failure occurs after the export phase (by executing an export alone) in which case I could proceed with the recreation of DB through import.
Exactly; just try to export your data first.