By stkalaitzis
Hi,
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
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!
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.
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:
[mysqld]
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.