{"id":214,"date":"2020-05-11T16:16:14","date_gmt":"2020-05-11T16:16:14","guid":{"rendered":"http:\/\/metajack.org\/blog\/?p=214"},"modified":"2020-05-11T16:20:58","modified_gmt":"2020-05-11T16:20:58","slug":"when-mysql-wont-start-due-to-innodb-errors","status":"publish","type":"post","link":"https:\/\/metajack.org\/blog\/2020\/05\/11\/when-mysql-wont-start-due-to-innodb-errors\/","title":{"rendered":"When mysql won&#8217;t start due to innodb errors"},"content":{"rendered":"\n<p>Over the years innodb has caused me more trouble than anything else in the LAMP stack. MyISAM tables seem to work and repair without issue. Innodb seem to be endless trouble. Alas, clients need them so I have to make them work.<\/p>\n\n\n\n<p>Today a mysql server crashed and wouldn&#8217;t restart. A few of the errors:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>File operation call: 'read' returned OS error 71.<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>InnoDB: Operating system error number 2 in a file operation<\/code><\/pre>\n\n\n\n<p>among others. I won&#8217;t get into the causes &#8211; I&#8217;m sure 99% is due to poor shutdowns and other issues that are not really the fault of mysql (other than the lack of graceful failure whichh myisam seems to be so good at).<\/p>\n\n\n\n<p>Here is a quick fix when under pressure &#8211; this won&#8217;t fix your problems if you have a single innodb table you need but if you have a mixed set of databases and tables this will get at least <em>something<\/em> working &#8211; which in my case was better than nothing.<\/p>\n\n\n\n<p>Note that everything I&#8217;m saying to do is very bad form and practice. But if you have critical databases that need to be up it may help you out. As always, <em>back everything up firs<\/em>t just in case. You&#8217;ll have a back-up of a broken database but perhaps it will be a bit <em>less<\/em> broke than the version you have if the following goes wrong.<\/p>\n\n\n\n<p>First find and move all databases with innodb tables to a temp directory :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir \/var\/lib\/tmp_disable\nfind \/var\/lib\/mysql -name \"*.ibd\" -print\n# you'll see various files inding in .ibd - look at the directory they are in (the database name) and move that dir out of the mysql data directory\nmv &lt;database-dir> \/var\/lib\/tmp_disable\n<\/code><\/pre>\n\n\n\n<p>Finally move the global .ibd and logs to the tmp directory: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mv \/var\/lib\/mysql\/ibdata1 \/var\/lib\/mysql\/ib_logfile* \/var\/lib\/tmp_disable<\/code><\/pre>\n\n\n\n<p>mysql won&#8217;t like this and it&#8217;s not really a good idea. However your mysql server should at least start now. A new (empty) ibdata1 will be created. This will break a lot of things if your data is stored in this global datafile. However if you have each innodb table writing to its own ibd (by setting innodb_file_per_table in \/etc\/my.cnf) you might be ok.<\/p>\n\n\n\n<p>Next, move each database back into \/var\/lib\/mysql on-by-one, restarting mysql each time to see if it will still start. What to do with the database that is causing the problem? No easy answer to that unfortunately. I usually build a temporary mysql server in a VPS to work on it. At least your overall server will run while you are able to troubleshoot the problem database table(s).<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over the years innodb has caused me more trouble than anything else in the LAMP stack. MyISAM tables seem to work and repair without issue. Innodb seem to be endless trouble. Alas, clients need them so I have to make them work. Today a mysql server crashed and wouldn&#8217;t restart. A few of the errors: &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/metajack.org\/blog\/2020\/05\/11\/when-mysql-wont-start-due-to-innodb-errors\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;When mysql won&#8217;t start due to innodb errors&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,2],"tags":[29,28],"class_list":["post-214","post","type-post","status-publish","format-standard","hentry","category-mysql","category-sysadmin","tag-innodb","tag-mysql","entry"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/posts\/214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/comments?post=214"}],"version-history":[{"count":2,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/posts\/214\/revisions"}],"predecessor-version":[{"id":216,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/posts\/214\/revisions\/216"}],"wp:attachment":[{"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/media?parent=214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/categories?post=214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/tags?post=214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}