{"id":1552,"date":"2020-05-04T17:40:53","date_gmt":"2020-05-04T15:40:53","guid":{"rendered":"https:\/\/www.wp-moon.com\/?p=1552"},"modified":"2020-05-14T11:57:32","modified_gmt":"2020-05-14T09:57:32","slug":"error-establishing-a-database-connection-when-everything-looks-good","status":"publish","type":"post","link":"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/","title":{"rendered":"Error establishing a database connection\u2026 when everything looks good!"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><p>[vc_row][vc_column][vc_custom_heading text=&#8221;Problem&#8221; use_theme_fonts=&#8221;yes&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]You have your WordPress installed. Everything is functional. One fine morning, your site displays this error.<\/p>\n<p>In a usual situation, you should check if the <em>wp-config.php<\/em> file is correctly filled in. Then, you test to access your database, everything seems normal. Finally, you quickly create a small script that tries to connect to your database with the same parameters as your WordPress installation&#8230; and it works.[\/vc_column_text][\/vc_column][\/vc_row][vc_row][vc_column][vc_custom_heading text=&#8221;The cause&#8221; use_theme_fonts=&#8221;yes&#8221;][vc_column_text]As said before, usually this error comes from the wp-config file which has a configuration error. It should therefore be checked first. Then, you should check that it is functional (by trying to access it) and contact your host if it is not the case, then if it is active that there is no hacking of your database (by looking at its size, by observing the tables, by comparing it to a backup&#8230;).<\/p>\n<p>If you have validated all these steps, there remains one cause that you can possibly identify by comparing your database with a recent backup: a data corruption in your database<\/p>\n<p>The error processed in this article can be triggered when the wp-options table is affected by a problem.[\/vc_column_text][\/vc_column][vc_column][vc_custom_heading text=&#8221;The solution&#8221; use_theme_fonts=&#8221;yes&#8221;][vc_column_text]The wp-options table contains general settings for your website, parameters for your plugins, themes&#8230; and some temporary data.<br \/>\nAmong these parameters, there is the URL of your site, and that&#8217;s what we&#8217;re going to be interested in.<\/p>\n<ul>\n<li>Connecting to your database<\/li>\n<li>If necessary, temporarily, you can upload a phpMyAdmin via (S)FTP to your site https:\/\/www.phpmyadmin.net\/downloads\/.<\/li>\n<li>Go to the wp-options table<\/li>\n<li>See if you can identify if the siteurl parameter is present and filled with the URL of your site.<\/li>\n<li>If not, execute the following query:<br \/>\n<code>INSERT INTO `wp_options` VALUES (1.0, 'siteurl', 'https:\/\/example.com\/', 'yes')<\/code><br \/>\nwhere <em>https:\/\/example.com<\/em> is to be replaced by the URL of your site<\/li>\n<\/ul>\n<p>If your site is working again, you will first need to make a full backup of your site (especially the database), but you will need to ask yourself how this problem could have occurred. It may be necessary to perform an audit of your website in order to identify any weaknesses or vulnerabilities that may have been exploited.<\/p>\n<p>Sometimes there may be several errors in your database. In addition, you can add the following line to your wp-config.php file:<\/p>\n<p><code>define('WP_ALLOW_REPAIR', true);<\/code><\/p>\n<p>then access the following URL: https:\/\/www.exemple.com\/wp-admin\/maint\/repair.php where https:\/\/exemple.com is to be replaced by the URL of your site.<br \/>\nThis will start the optimization and correction of your database.[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>You have your WordPress installed. Everything is functional. One fine morning, your site displays this error.<\/p>\n<p>In a usual situation, you should check if the wp-config.php file is correctly filled in. Then, you test to access your database, everything seems normal. Finally, you quickly create a small script that tries to connect to your database with the same parameters as your WordPress installation&#8230; and it works.<\/p>\n","protected":false},"author":2,"featured_media":1510,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[108,102,65],"class_list":["post-1552","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-fix-errors","tag-connection","tag-database","tag-error-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Error establishing a database connection\u2026 when everything looks good! - WP Moon<\/title>\n<meta name=\"description\" content=\"You have your WordPress installed. Everything is functional. One fine morning, your site displays this error.  In a usual situation, you should check if the wp-config.php file is correctly filled in. Then, you test to access your database, everything seems normal. Finally, you quickly create a small script that tries to connect to your database with the same parameters as your WordPress installation... and it works.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Error establishing a database connection\u2026 when everything looks good! - WP Moon\" \/>\n<meta property=\"og:description\" content=\"You have your WordPress installed. Everything is functional. One fine morning, your site displays this error.  In a usual situation, you should check if the wp-config.php file is correctly filled in. Then, you test to access your database, everything seems normal. Finally, you quickly create a small script that tries to connect to your database with the same parameters as your WordPress installation... and it works.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/\" \/>\n<meta property=\"og:site_name\" content=\"WP Moon\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/wpmoonwebsite\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-04T15:40:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-05-14T09:57:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wp-moon.com\/wp-content\/uploads\/2020\/04\/error-establishing-a-database-connection-alors-que-tout-semble-bon.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1507\" \/>\n\t<meta property=\"og:image:height\" content=\"941\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Alexandre G\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@alexgaboriau\" \/>\n<meta name=\"twitter:site\" content=\"@WPMoon4\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alexandre G\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Error establishing a database connection\u2026 when everything looks good! - WP Moon","description":"You have your WordPress installed. Everything is functional. One fine morning, your site displays this error.  In a usual situation, you should check if the wp-config.php file is correctly filled in. Then, you test to access your database, everything seems normal. Finally, you quickly create a small script that tries to connect to your database with the same parameters as your WordPress installation... and it works.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/","og_locale":"en_US","og_type":"article","og_title":"Error establishing a database connection\u2026 when everything looks good! - WP Moon","og_description":"You have your WordPress installed. Everything is functional. One fine morning, your site displays this error.  In a usual situation, you should check if the wp-config.php file is correctly filled in. Then, you test to access your database, everything seems normal. Finally, you quickly create a small script that tries to connect to your database with the same parameters as your WordPress installation... and it works.","og_url":"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/","og_site_name":"WP Moon","article_publisher":"https:\/\/www.facebook.com\/wpmoonwebsite","article_published_time":"2020-05-04T15:40:53+00:00","article_modified_time":"2020-05-14T09:57:32+00:00","og_image":[{"width":1507,"height":941,"url":"https:\/\/www.wp-moon.com\/wp-content\/uploads\/2020\/04\/error-establishing-a-database-connection-alors-que-tout-semble-bon.jpg","type":"image\/jpeg"}],"author":"Alexandre G","twitter_card":"summary_large_image","twitter_creator":"@alexgaboriau","twitter_site":"@WPMoon4","twitter_misc":{"Written by":"Alexandre G","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/#article","isPartOf":{"@id":"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/"},"author":{"name":"Alexandre G","@id":"https:\/\/www.wp-moon.com\/en\/#\/schema\/person\/72a64e6910977ec9e4b32fd8da54369d"},"headline":"Error establishing a database connection\u2026 when everything looks good!","datePublished":"2020-05-04T15:40:53+00:00","dateModified":"2020-05-14T09:57:32+00:00","mainEntityOfPage":{"@id":"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/"},"wordCount":495,"commentCount":0,"publisher":{"@id":"https:\/\/www.wp-moon.com\/en\/#organization"},"image":{"@id":"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wp-moon.com\/wp-content\/uploads\/2020\/04\/error-establishing-a-database-connection-alors-que-tout-semble-bon.jpg","keywords":["connection","database","error"],"articleSection":["Fix Errors"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/","url":"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/","name":"Error establishing a database connection\u2026 when everything looks good! - WP Moon","isPartOf":{"@id":"https:\/\/www.wp-moon.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/#primaryimage"},"image":{"@id":"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wp-moon.com\/wp-content\/uploads\/2020\/04\/error-establishing-a-database-connection-alors-que-tout-semble-bon.jpg","datePublished":"2020-05-04T15:40:53+00:00","dateModified":"2020-05-14T09:57:32+00:00","description":"You have your WordPress installed. Everything is functional. One fine morning, your site displays this error. In a usual situation, you should check if the wp-config.php file is correctly filled in. Then, you test to access your database, everything seems normal. Finally, you quickly create a small script that tries to connect to your database with the same parameters as your WordPress installation... and it works.","breadcrumb":{"@id":"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/#primaryimage","url":"https:\/\/www.wp-moon.com\/wp-content\/uploads\/2020\/04\/error-establishing-a-database-connection-alors-que-tout-semble-bon.jpg","contentUrl":"https:\/\/www.wp-moon.com\/wp-content\/uploads\/2020\/04\/error-establishing-a-database-connection-alors-que-tout-semble-bon.jpg","width":1507,"height":941},{"@type":"BreadcrumbList","@id":"https:\/\/www.wp-moon.com\/en\/error-establishing-a-database-connection-when-everything-looks-good\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.wp-moon.com\/en\/"},{"@type":"ListItem","position":2,"name":"Fix Errors","item":"https:\/\/www.wp-moon.com\/en\/category\/fix-errors\/"},{"@type":"ListItem","position":3,"name":"Error establishing a database connection\u2026 when everything looks good!"}]},{"@type":"WebSite","@id":"https:\/\/www.wp-moon.com\/en\/#website","url":"https:\/\/www.wp-moon.com\/en\/","name":"WP Moon","description":"","publisher":{"@id":"https:\/\/www.wp-moon.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wp-moon.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.wp-moon.com\/en\/#organization","name":"WP Moon","url":"https:\/\/www.wp-moon.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wp-moon.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/www.wp-moon.com\/wp-content\/uploads\/2020\/02\/logo.png","contentUrl":"https:\/\/www.wp-moon.com\/wp-content\/uploads\/2020\/02\/logo.png","width":290,"height":95,"caption":"WP Moon"},"image":{"@id":"https:\/\/www.wp-moon.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/wpmoonwebsite","https:\/\/x.com\/WPMoon4"]},{"@type":"Person","@id":"https:\/\/www.wp-moon.com\/en\/#\/schema\/person\/72a64e6910977ec9e4b32fd8da54369d","name":"Alexandre G","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wp-moon.com\/wp-content\/uploads\/2023\/09\/312419460_10229483707296045_2919774527885824513_n-100x100.jpg","url":"https:\/\/www.wp-moon.com\/wp-content\/uploads\/2023\/09\/312419460_10229483707296045_2919774527885824513_n-100x100.jpg","contentUrl":"https:\/\/www.wp-moon.com\/wp-content\/uploads\/2023\/09\/312419460_10229483707296045_2919774527885824513_n-100x100.jpg","caption":"Alexandre G"},"description":"Alexandre, Web Developer &amp; Website Editor. I've been using WordPress for over 10 years in my professional environment and on personal projects. I created WP Moon to teach you how to use this CMS, solve your problems and show you all the tricks.","sameAs":["https:\/\/www.croque-pixel.com\/","https:\/\/x.com\/alexgaboriau","https:\/\/www.youtube.com\/@wp_moon\/videos"],"url":"https:\/\/www.wp-moon.com\/en\/author\/wp-moon\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wp-moon.com\/en\/wp-json\/wp\/v2\/posts\/1552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wp-moon.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wp-moon.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wp-moon.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wp-moon.com\/en\/wp-json\/wp\/v2\/comments?post=1552"}],"version-history":[{"count":0,"href":"https:\/\/www.wp-moon.com\/en\/wp-json\/wp\/v2\/posts\/1552\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wp-moon.com\/en\/wp-json\/wp\/v2\/media\/1510"}],"wp:attachment":[{"href":"https:\/\/www.wp-moon.com\/en\/wp-json\/wp\/v2\/media?parent=1552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wp-moon.com\/en\/wp-json\/wp\/v2\/categories?post=1552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wp-moon.com\/en\/wp-json\/wp\/v2\/tags?post=1552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}