{"id":978,"date":"2025-05-14T09:19:36","date_gmt":"2025-05-14T07:19:36","guid":{"rendered":"https:\/\/mic.st\/blog\/?p=978"},"modified":"2025-05-21T13:25:48","modified_gmt":"2025-05-21T11:25:48","slug":"error-establishing-a-database-connection-and-how-to-fix-this","status":"publish","type":"post","link":"https:\/\/mic.st\/blog\/error-establishing-a-database-connection-and-how-to-fix-this\/","title":{"rendered":"Error establishing a database connection on WordPress Blog"},"content":{"rendered":"\n<p>I have to admit that I do not really regularily write into this blog. Usually, whenever I have an idea, I write down a first draft and finish the post later, sometimes weeks later. Some days ago I had such an idea and realized that the blog was completely unreachable. Not sure for how long actually. The only thing it showed was this error saying &#8220;Error establishing a database connection&#8221; (see image below).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"792\" height=\"158\" src=\"https:\/\/mic.st\/blog\/wp-content\/uploads\/2025\/05\/image.png\" alt=\"Error message saying &quot;Error establishing a database connection&quot;\" class=\"wp-image-979\" srcset=\"https:\/\/mic.st\/blog\/wp-content\/uploads\/2025\/05\/image.png 792w, https:\/\/mic.st\/blog\/wp-content\/uploads\/2025\/05\/image-300x60.png 300w, https:\/\/mic.st\/blog\/wp-content\/uploads\/2025\/05\/image-768x153.png 768w\" sizes=\"auto, (max-width: 792px) 100vw, 792px\" \/><figcaption class=\"wp-element-caption\">The error show when entering https:\/\/mic.st, saying &#8220;Error establishing a database connection&#8221;.<\/figcaption><\/figure>\n<\/div>\n\n\n<p><strong>Update<\/strong>: If you are lucky, everything is a little easier to fix as described in my older article:<a href=\" https:\/\/mic.st\/blog\/how-to-fix-error-establishing-a-database-connection-for-wordpress\/\"> https:\/\/mic.st\/blog\/how-to-fix-error-establishing-a-database-connection-for-wordpress\/<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Investigating the error<\/h2>\n\n\n\n<p>As nothing did work anymore from a frontend perspective, I quickly went into the webserver to find out what&#8217;s going on.<\/p>\n\n\n\n<p>First of all, it was years ago since setting up the wordpress website so I was not even aware which kind of database was actually supposed to run. After finding out that it&#8217;s &#8220;mariadb&#8221;, I just wanted to try restarting the database service. A quick Google search lead to this: <a href=\"https:\/\/mariadb.com\/docs\/server\/service-management\/operations\/start-stop-status\/\" target=\"_blank\" rel=\"noopener\">https:\/\/mariadb.com\/docs\/server\/service-management\/operations\/start-stop-status\/<\/a><\/p>\n\n\n\n<p>Restarting can be done using:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">sudo systemctl restart mariadb<\/code><\/span><\/pre>\n\n\n<p>Unfortunately, this just did not work. It exited with following error:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">Job <span class=\"hljs-keyword\">for<\/span> mariadb.service failed because the control process exited with error code.\nSee <span class=\"hljs-string\">\"systemctl status mariadb.service\"<\/span> and <span class=\"hljs-string\">\"journalctl -xe\"<\/span> <span class=\"hljs-keyword\">for<\/span> details.<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>As mentioned in the error, running <code>systemctl status mariadb.service<\/code> can give you a little more information about what did actually go wrong. As the error itself is not really giving you a lot.<\/p>\n\n\n\n<p>The error mentioned something regarding not enough space left. Which was a relieve as it sounded like I can just delete some files and everything should work again.<\/p>\n\n\n\n<p>I found out that the drive was actually pretty full. You might be able do that via your server panel (which I initally did) or you can run the following:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">df -h<\/code><\/span><\/pre>\n\n\n<p>The <code>-h<\/code> argument does just mean &#8220;human readable&#8221;. You will get a nice output about your drives and space used which does give you a first indication of where you should free up some space. My main drive did show around of 99% space used, which obviously is a little too much. A little more about this command you can find here for example: <a href=\"https:\/\/opensource.com\/article\/18\/7\/how-check-free-disk-space-linux\" target=\"_blank\" rel=\"noopener\">https:\/\/opensource.com\/article\/18\/7\/how-check-free-disk-space-linux<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Where to save space?<\/h2>\n\n\n\n<p>To gain more insights on where to actually save space, it does make sense to have a look on the directories themselves. The command line tool <code>ncdu<\/code> (see <a href=\"https:\/\/dev.yorhel.nl\/ncdu\" target=\"_blank\" rel=\"noopener\">https:\/\/dev.yorhel.nl\/ncdu<\/a>) is of great use here as you quickly gain insights on where space is used. It is a fast and interactive tool. However, it is probably not installed by default with your Linux distribution. In my case I was not able to install it as that much space was taken by &#8220;whatever&#8221; (as I still did not know).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Find space used without ncdu<\/h2>\n\n\n\n<p>Of course you can also find out about space used without <code>ncdu<\/code>. For finding out about directories themselves, you can use <code>du<\/code> or more specifically <code>du -hs<\/code> to find out about the size of a given directory. It is using the one you are currently in if no path is passed.<\/p>\n\n\n\n<p>A good starting point is using:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\"> du -h --max-depth=1 \/ | sort -h<\/code><\/span><\/pre>\n\n\n<p>It gives you the file size of anything located under <code>\/<\/code> going down with a depth of one (as you do not want to the size of each and every directory on your filesystem). It is sorted so that you can easily spot the largest directory. Which in my case was <code>var<\/code>.<\/p>\n\n\n\n<p>You can go down then directory by directory until finding out what is taking most space.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Delete stuff<\/h2>\n\n\n\n<p>If you are not aware of what the stuff is you intend to delete: Google first! You can easily break your system by deleting the wrong things. Also consider doing a backup first via your webserver provider before deleting anything.<\/p>\n\n\n\n<p>Some ideas for stuff to delete:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Unused docker containers<\/li>\n\n\n\n<li>old log files (they can take up a huge amount if never cleaned up!). <strong>Do not delete any mysql related logfiles for now!<\/strong><\/li>\n\n\n\n<li>Cronjob output (this was a couple of gigabytes in my case, I also removed the associated cronjob as it was not needed anyways)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Trying to restarting the database service<\/h2>\n\n\n\n<p>I cleaned up a lot and tried restarting and&#8230; it still did not work.<\/p>\n\n\n\n<p>Now it is time to have a closer look into the mysql logs. Their location is depending on your setup. You can find out the location via <code>mysqld --print-defaults<\/code><\/p>\n\n\n\n<p>In my case they were located under <code>\/var\/log\/mysql\/error.log<\/code>.<\/p>\n\n\n\n<p>The log file included this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\">2025<span class=\"hljs-selector-tag\">-05-09<\/span> 15<span class=\"hljs-selector-pseudo\">:18<\/span><span class=\"hljs-selector-pseudo\">:59<\/span> 0 <span class=\"hljs-selector-attr\">&#91;ERROR]<\/span> <span class=\"hljs-selector-tag\">Aria<\/span> <span class=\"hljs-selector-tag\">engine<\/span> <span class=\"hljs-selector-tag\">is<\/span> <span class=\"hljs-selector-tag\">not<\/span> <span class=\"hljs-selector-tag\">enabled<\/span> <span class=\"hljs-selector-tag\">or<\/span> <span class=\"hljs-selector-tag\">did<\/span> <span class=\"hljs-selector-tag\">not<\/span> <span class=\"hljs-selector-tag\">start<\/span>. <span class=\"hljs-selector-tag\">The<\/span> <span class=\"hljs-selector-tag\">Aria<\/span> <span class=\"hljs-selector-tag\">engine<\/span> <span class=\"hljs-selector-tag\">must<\/span> <span class=\"hljs-selector-tag\">be<\/span> <span class=\"hljs-selector-tag\">enabled<\/span> <span class=\"hljs-selector-tag\">to<\/span> <span class=\"hljs-selector-tag\">continue<\/span> <span class=\"hljs-selector-tag\">as<\/span> <span class=\"hljs-selector-tag\">mysqld<\/span> <span class=\"hljs-selector-tag\">was<\/span> <span class=\"hljs-selector-tag\">configured<\/span> <span class=\"hljs-selector-tag\">with<\/span> <span class=\"hljs-selector-tag\">--with-aria-tmp-tables<\/span>\n2025<span class=\"hljs-selector-tag\">-05-09<\/span> 15<span class=\"hljs-selector-pseudo\">:18<\/span><span class=\"hljs-selector-pseudo\">:59<\/span> 0 <span class=\"hljs-selector-attr\">&#91;ERROR]<\/span> <span class=\"hljs-selector-tag\">Aborting<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>After a quick Google search I found that it might be fixed when renaming a certain &#8220;aria&#8221; file. More information on this can be found here: <a href=\"https:\/\/support.plesk.com\/hc\/en-us\/articles\/12377243101591-MariaDB-fails-to-start-Aria-engine-is-not-enabled-or-did-not-start\" target=\"_blank\" rel=\"noopener\">https:\/\/support.plesk.com\/hc\/en-us\/articles\/12377243101591-MariaDB-fails-to-start-Aria-engine-is-not-enabled-or-did-not-start<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">It works!<\/h2>\n\n\n\n<p>And now&#8230; By using <code>sudo systemctl restart mariadb<\/code> restarting works \ud83d\ude80 Hooray!<\/p>\n\n\n\n<p>The blog and everything is accessible again, no data seems to be lost. Peeew!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion or what did we learn<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Have backups in place<\/li>\n\n\n\n<li>Pay attention to the space used on your webserver\n<ul class=\"wp-block-list\">\n<li>It might just crash, service might shutdown and things might be unable to be restared<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Watch out for Cronjobs running wild. Check regularily or ideally set them up so that they cannot really clog your space<\/li>\n\n\n\n<li>Do install <code>ncdu<\/code> now if you do not have already. It is a great tool saving you a lot of time.<\/li>\n\n\n\n<li>Really do google any file or directory you want to delete and are not sure about. It is easy to break stuff.<\/li>\n<\/ol>\n\n\n\n<p>Hope you learned something today, happy webserver debugging!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have to admit that I do not really regularily write into this blog. Usually, whenever I have an idea, I write down a first draft and finish the post later, sometimes weeks later. Some days ago I had such an idea and realized that the blog was completely unreachable. Not sure for how long&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-978","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"_links":{"self":[{"href":"https:\/\/mic.st\/blog\/wp-json\/wp\/v2\/posts\/978","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mic.st\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mic.st\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mic.st\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mic.st\/blog\/wp-json\/wp\/v2\/comments?post=978"}],"version-history":[{"count":7,"href":"https:\/\/mic.st\/blog\/wp-json\/wp\/v2\/posts\/978\/revisions"}],"predecessor-version":[{"id":999,"href":"https:\/\/mic.st\/blog\/wp-json\/wp\/v2\/posts\/978\/revisions\/999"}],"wp:attachment":[{"href":"https:\/\/mic.st\/blog\/wp-json\/wp\/v2\/media?parent=978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mic.st\/blog\/wp-json\/wp\/v2\/categories?post=978"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mic.st\/blog\/wp-json\/wp\/v2\/tags?post=978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}