Crashes database and MySQL failed to start,


there is an error in database that can’t restart, the command “sudo service MySQL start” always failed,

the database crashed when I tried to optimize a table, there is 5 websites down now,

can you please support?

Thanks, Stathis

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

What does the log say?

For the innodb issue that you mentioned it’s most likely because you have some text or blob fields inside of your database that are too large given the settings for your MySQL sever and they need to be tuned so that you can parse your transaction logs.

To do this you will want to review your /etc/my.cnf variables and tune them up.

Specfically the following:

innodb_log_buffer_size          = 64M
innodb_buffer_pool_size         = 1G
innodb_log_file_size            = 512M

Though you may want to check your defaults and scale from there, by using a factor of 4x.

Then you want to make sure that any running transactions have been processed from your existing logs to do that you will want to force them to be written:

mysql -uroot -p -e"SET GLOBAL innodb_fast_shutdown = 0;"

If your MySQL server isn’t running that will probably fail, so you can proceed to the next step, which is either to delete or move your existing logs. If you are worried you have unprocessed transactions you can just move them otherwise:

service mysql stop
rm -f /var/lib/mysql/ib_logfile*

Now that you’ve updated your mysqld settings for your innodb logs you can restart mysql:

service mysql start

And the service should start up just fine. If the earlier attempt to set innodb_fast_shutdown failed you will want to do it again now so that future shutdowns commit all transactions:

mysql -uroot -p -e"SET GLOBAL innodb_fast_shutdown = 0;"

Now hopefully everything is back up and running for you.

There are a couple of potential issues so you may need to do some diagnostic work to determine which it is.

First ensure that any stale processes of mysqld aren’t running using ps aux | grep mysql and killing them off if necessary.

Then without more information it is very likely that you may need to run a repair on your tables and then attempt to restart mysql:

myisamchk --safe-recover --force --sort_buffer_size=2G --key_buffer_size=2G /var/lib/mysql/*/*.MYI

This is assuming that your mysql databases are stored in /var/lib/mysql.

Then when you attempt to restart, hopefully things work, if not check where your mysql error log resides and tail it to see if there are any more detailed error messages that are present. It maybe related to a corrupt table, broken permissions, or perhaps a socket connection that isn’t being initialized appropriately.

Hopefully though the myisamchk will fix things up for you and you’ll be able to restart without any further issues.