Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
Coupe WPB
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Comment Corrigé l’erreur d’établissement d’une connexion à la base de données dans WordPress

La notification « Erreur lors de l’établissement de la connexion à la base de données » apparaît-elle dans WordPress ?

Il s’agit d’une erreur fatale qui rend votre site inaccessible aux utilisateurs/utilisatrices. Elle se produit lorsque WordPress ne parvient pas à établir une connexion avec la base de données. Étant donné que de multiples facteurs peuvent affecter cette connexion, cette erreur peut être un peu difficile à dépanner pour les débutants.

Dans cet article, nous allons vous afficher comment corriger facilement le message  » Erreur d’établissement d’une connexion à la base de données  » sur votre site WordPress, étape par étape.

Fix the Error Establishing a Database Connection in WordPress

Quelle est la cause de l’erreur d’établissement d’une connexion à la base de données dans WordPress ?

Une base de données est un logiciel qui permet de stocker, d’organiser et d’extraire facilement des données d’autres logiciels.

En tant que système de gestion de contenu, WordPress utilise une base de données pour stocker tout votre contenu et les autres données de votre site. Il se connecte ensuite à la base de données chaque fois que quelqu’un visite votre site.

WordPress a besoin des informations suivantes pour se connecter à la base de données :

  • Nom de la base de données
  • Nom d’utilisateur et mot de passe de la base de données
  • Serveur de base de données

Ces informations sont stockées dans votre fichier de configuration WordPress, qui s’appelle wp-config.php.

Si l’une de ces informations est incorrecte, WordPress ne parviendra pas à se connecter à votre serveur de base de données et vous verrez apparaître l’erreur « Erreur dans l’établissement de la connexion à la base de données ».

Database connection error in WordPress

Il s’agit de l’une des erreurs les plus courantes de WordPress. Outre les informations d’identification incorrectes, cette erreur peut également apparaître si le serveur de données est en panne ou si les fichiers de la base de données sont corrompus.

Ceci étant dit, voyons comment corriger le problème  » Erreur lors de l’établissement de la connexion à la base de données  » dans WordPress avec un dépannage étape par étape.

1. Vérifiez les infos de la base de données de WordPress

La raison la plus fréquente de l’erreur de connexion à la base de données est une info de connexion incorrecte. Si vous avez récemment déplacé votre site WordPress vers un nouvel hébergeur, c’est probablement la cause du problème.

Les informations d’identification de votre base de données WordPress sont stockées dans le fichier wp-config.php. Il s’agit du fichier de configuration de WordPress qui contient des réglages importants, notamment des informations sur la base de données.

Si vous n’avez jamais modifié un fichier wp-config.php auparavant, consultez notre guide du débutant sur la manière de modifier le fichier wp-config.php pour plus d’instructions.

Vous rechercherez les lignes suivantes dans le fichier wp-config.php :

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

Confirmez ici que les informations relatives au nom de la base de données, à l’identifiant, au mot de passe et à l’hébergeur de la base de données sont correctes.

Vous pouvez confirmer ces informations à partir du tableau de bord de votre compte d’hébergement WordPress. Pour ce tutoriel, nous utiliserons Bluehost, mais le processus sera similaire pour d’autres panneaux d’hébergement également.

Après vous être connecté, cliquez sur l’onglet « Site » dans la colonne de gauche, puis passez à l’onglet « Avancé ». Défilez ensuite jusqu’à la section « Base de données » et cliquez sur le bouton « Gérer » situé à côté.

Click the Manage button next to the Database section

Cela ouvrira la page des bases de données MySQL dans cPanel dans une nouvelle fenêtre.

Ici, vous pouvez trouver le nom de votre base de données et votre identifiant dans la section  » Base de données actuelle « . N’oubliez pas de copier et de coller ces informations dans un bloc-notes afin de les ajouter au fichier wp-config.

Find your database name and username in the Current Databases section

Ensuite, défilez jusqu’à la section « Utilisateurs/utilisatrices actuels », où vous pouvez cliquer sur le lien « Modifier le mot de passe » à côté du nom de votre base de données.

Vous accéderez à un nouvel écran, où vous pourrez modifier le mot de passe de la base de données à votre convenance.

Change your database password

Une fois que vous avez confirmé tous les détails de votre base de données, vous pouvez modifier ces informations dans votre fichier wp-config.php si nécessaire.

Après cela, réessayez de visiter votre site pour voir si l’erreur de connexion à la base de données a disparu.

Si l’erreur persiste, cela signifie que quelque chose d’autre ne va pas.

2. Vérifiez les informations relatives à l’hébergeur de votre base de données

Si vous êtes certain que le nom de votre base de données, votre identifiant et votre mot de passe sont corrects, vous devez alors vous assurer que vous utilisez les bonnes informations sur l’hébergeur de la base de données.

La plupart des entreprises d’hébergement WordPress utilisent localhost comme hébergeur de votre base de données. Cependant, certaines entreprises d’hébergement WordPress infogérées utilisent des serveurs distincts pour héberger les bases de données. Dans ce cas, l’hébergeur de votre base de données ne sera pas localhost.

Cela signifie que vous devrez contacter votre entreprise d’hébergement WordPress pour confirmer ces détails.

3. Réparer la base de données de WordPress

Maintenant, il se peut que vous obteniez une erreur différente dans le tableau de bord wp-admin comme « Une ou plusieurs tables de la base de données sont indisponibles » ou « La base de données peut avoir besoin d’être réparée ». Dans ce cas, vous devez réparer votre base de données.

Vous pouvez le faire en ajoutant la ligne suivante dans votre fichier wp-config.php. Confirmez-vous que vous l’ajoutez juste avant la ligne « C’est tout, arrêtez les modifications ! Bon blog » :

define('WP_ALLOW_REPAIR', true);

Une fois que vous avez fait cela, vous pouvez voir les réglages en visitant cette page : http://www.yoursite.com/wp-admin/maint/repair.php. Confirmez simplement que vous remplacez yoursite.com par votre propre nom de domaine.

Ici, vous devez cliquer sur le bouton « Réparer la base de données » pour lancer le processus.

Repair WordPress database

Note : L’utilisateur n’a pas besoin d’être connecté pour accéder à la page de réparation de la base de données. Une fois la réparation et l’optimisation de votre base de données terminées, retirez cette ligne de code de votre fichier wp-config.php.

Toutefois, si vous ne souhaitez pas ajouter de code à votre site, vous pouvez également réparer votre base de données à partir du cPanel de votre compte d’hébergement.

Rendez-vous sur votre compte hébergeur, où vous devez ouvrir la page ‘Sites Web’ dans la colonne de gauche. Ensuite, passez à l’onglet ‘Avancé’ et cliquez sur le bouton ‘Gérer’ dans la section Base de données.

Click the Manage button next to the Database section

Cela ouvrira cPanel dans un nouvel onglet. Défilez vers le bas jusqu’à la section ‘Modifier les bases de données’ et choisissez le nom de votre base de données dans le menu déroulant ‘Réparer la base de données’.

Une fois que vous avez fait cela, cliquez simplement sur le bouton « Réparer la base de données » pour lancer le processus.

Click the Repair database button

Le panneau d’hébergement va maintenant réparer automatiquement votre base de données.

Une fois le processus terminé, un message de réussite s’affiche.

Database repair success message

Vous pouvez maintenant visiter votre site WordPress pour voir si l’erreur a été résolue ou non.

4. Vérifier si votre serveur de base de données est en panne

Si tout semble correct et que WordPress ne parvient toujours pas à se connecter à la base de données, il se peut que votre serveur de base de données(serveur MySQL) soit en panne.

Cela peut se produire en raison d’un trafic important sur un serveur. Le serveur de votre hébergeur ne peut tout simplement pas supporter la charge (surtout si vous êtes en hébergement partagé).

De ce fait, votre site sera lent, et certains utilisateurs/utilisatrices pourront même obtenir une erreur. Dans ce cas, vous devez contacter votre fournisseur d’hébergement par téléphone ou par discussion directe et lui demander si votre serveur MySQL est responsive.

En outre, si d’autres sites fonctionnent sur le même serveur, vous pouvez vérifier ces sites pour confirmer que votre serveur SQL est hors service.

Si vous n’avez pas d’autre site sur le même compte d’hébergeur, il vous suffit de vous rendre sur votre Tableau de bord et de passer à l’onglet « Avancé ».

Cliquez ensuite sur le bouton « Gérer » à côté de la section phpMyAdmin.

Click the Manage button next to the PHPMyAdmin option

Cela ouvrira phpMyAdmin dans une nouvelle fenêtre, où vous devrez cliquer sur l’option « Base de données » en haut.

Cliquez ensuite sur le nom de votre base de données pour accéder à ses Réglages. Si vous y parvenez, il est temps de vérifier si l’utilisateur de votre base de données dispose de droits suffisants.

Connect PHPMyAdmin with your database

Pour ce faire, vous devez créer un nouveau fichier appelé testconnection.PHP et y coller le code suivant :

<?php
$link = mysqli_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>

En collant le code, veillez à remplacer l’identifiant et le mot de passe par les vôtres. Vous pouvez maintenant téléverser ce fichier sur votre site et y accéder via un navigateur web.

Si le script se connecte bien, cela signifie que votre compte dispose de droits suffisants et que l’erreur provient d’une autre source.

Maintenant, vous devez retourner à votre fichier wp-config et l’analyser pour vous assurer que tous les détails sont exacts et sans fautes de frappe.

Autres solutions qui ont fonctionné pour les utilisateurs/utilisatrices

Si les astuces de dépannage mentionnées ci-dessus ne parviennent pas à corriger l’erreur de connexion à la base de données sur votre site, vous pouvez essayer ces étapes supplémentaires.

Comme l’ont signalé nos utilisateurs/utilisatrices, ces étapes ont aidé certains d’entre eux à résoudre l’erreur de connexion à la base de données sur leur site.

1. Mettre à jour l’URL du site WordPress

Vous pouvez essayer de mettre à jour l’URL du site WordPress en utilisant phpMyAdmin dans cPanel.

Il vous suffit d’accéder à phpMyAdmin depuis le tableau de bord de votre compte hébergeur et de sélectionner votre base de données WordPress dans la liste.

Passez ensuite au menu SQL en haut de la page et saisissez la requête MySQL suivante :

UPDATE wp_options SET option_value='YOUR_SITE_URL' WHERE option_name='siteurl'

Il devrait ressembler à ceci :

Change site URL

N’oubliez pas d’indiquer l’URL de votre site et de modifier wp_options en fonction du nom de votre table, car il se peut que vous ayez modifié le préfixe de la table WordPress.

2. Redémarrage du serveur web

Les utilisateurs/utilisatrices de serveurs dédiés, de serveurs locaux et de serveurs privés virtuels (VPS) peuvent essayer de redémarrer leurs serveurs.

Cette opération redémarre votre serveur web et votre base de données, ce qui peut corriger certains problèmes temporaires à l’origine de l’erreur.

3. Demander de l’aide

Si tout le reste échoue, alors vous devrez peut-être contacter votre entreprise d’hébergement web. Toutes les bonnes entreprises d’hébergement WordPress vous aideront à dépanner le problème, vous indiqueront la bonne direction, voire le corrigeront pour vous.

Vous pouvez également embaucher des développeurs/développeuses WordPress en utilisant une plateforme comme WPBeginner Pro Services pour vous aider à corriger ce problème à des tarifs raisonnables. Nous avons une équipe dédiée de développeurs/développeuses experts à qui vous pouvez faire confiance pour résoudre tous vos problèmes WordPress.

WPBeginner Pro Services

De plus, vous pouvez utiliser le service pour la maintenance de votre site, la réparation de sites piratés, l’optimisation de la vitesse, la reconstruction de sites web et l’optimisation du référencement.

Nous espérons que cet article vous a aidé à corriger le problème  » Erreur lors de l’établissement d’une connexion à la base de données  » sur WordPress. Vous pouvez également consulter notre guide de dépannage WordPress pour des astuces sur la résolution des problèmes WordPress par vous-même, ou nos choix d’experts des meilleurs outils pour les développeurs/développeuses freelances WordPress.

Si vous avez aimé cet article, veuillez alors vous abonner à notre chaîne YouTube pour obtenir des tutoriels vidéo sur WordPress. Vous pouvez également nous trouver sur Twitter et Facebook.

Divulgation : Notre contenu est soutenu par les lecteurs. Cela signifie que si vous cliquez sur certains de nos liens, nous pouvons gagner une commission. Consultez comment WPBeginner est financé, pourquoi cela compte et comment vous pouvez nous soutenir. Voici notre processus éditorial.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

L'ultime WordPress Toolkit

Accédez GRATUITEMENT à notre boîte à outils - une collection de produits et de ressources liés à WordPress que tous les professionnels devraient avoir !

Reader Interactions

661 commentairesLaisser une réponse

  1. Syed Balkhi

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Javatechig

    Lovely. You saved my day.

  3. CE

    Thank you!!!!!!!! Worked like a charm!!

    • Mark Larson

      You’re so helpful! All my writing was saved! Yes, I need to do a backup… I did one! Thanks so much, this is just the resource I needed. Luckily Google pulled it right up.

  4. Michael Simoni

    I have a test wordpress installation on my home computer running on fedora. I moved/reinstalled the computer with a recent copy of fedora. I restored the database and the wordpress installation. Everything should have been fine except I had the « cannot connect to the database » error. I have had this wordpress installation for a long time. Turns out that when I moved to the new server I also got a new my.cnf. Now I checked it and made everything the same but for some reason i did not add the following line in /etc/my.cnf. Maybe i just wanted to see what would happen. hmmm…what does this button do…..
    # Default to using old password format for compatibility with mysql 3.x
    # clients (those using the mysqlclient10 compatibility package).
    old_passwords=1
    After I added that line, the database connection problem was fixed.
    So I need to drop that user and recreate it with the new password format.
    Note I also have
    skip-networking
    in /etc/my.cnf and….it works. That keeps mysql off the network, including 127.0.0.1. It’s just one less entry point for the mischief-makers.

  5. Matt

    I had a database-connection-error on a client’s site and could access the database via PHPMyAdmin but running the testconnect.php file suggested above came up with a response unlisted in this article:

    « PHP Warning: mysql_connect(): No connection could be made because the target machine actively refused it. »

    I got in touch with Fasthosts who my clients were with and it turned out that they had issues integrating PHP5.4 « and the only fix is to reset the MySQL database user password. »

    So if you’re in that boat, then you may be able to fix it by accessing the database via PHPMyAdmin and running the query:

    SET SESSION old_passwords = 0;
    SET PASSWORD = PASSWORD(‘databasepasswordgoeshere’);

    !! IMPORTANT NOTE !! : make sure you get ‘databasepasswordgoeshere’ correct otherwise you’ll be resetting your db password to something new rather than the same password and it could break your site even further!

  6. Terry

    I must be really dumb! i understand a little of wordpress but this all sounds way out of my leage.

    I have tried to do exactly what you have said and this is what I get

    Warning: Cannot modify header information – headers already sent by (output started at /customers/8/a/3/chigwelltkd.com/httpd.www/wordpress/wp-config.php:2) in /customers/8/a/3/chigwelltkd.com/httpd.www/wordpress/wp-includes/functions.php on line 2801
    Error establishing a database connection.

    I have no idea what to do next!!!

    Not only have i lost the site from the web but I know cannot get in to wordpress admin.

    IS THERE ANY HOPE!!!!!

  7. Rowan Weismiller

    Thanks so much for writing this post, it saved me quite a bit of time and a lot of headaches. Cheers!

  8. SH

    Solved my issue in less than 10mins cause of this article
    YOUR ARE DOPE…you mean business

    Thanks a mil!!!

  9. Nayonika

    This tutorial has really helped solving my problem!! Thanx a ton!

  10. Lyndsay

    Thanks a lot, this helped me fix my websites!

  11. Sumi Ghosh

    Hi,

    Recently i uploaded a theme to the wordpress site, i have also uploaded the local database. I have modified my wp-config file too. Still i am getting error database connection error. When i opened my wp-admin it redirecting to wp-login.

    Can i know what might be the problem?

    • WPBeginner Support

      We think its normal behavior for wordpress to redirect you to wp-login.php when you try to access wp-admin directory. Can you please explain further? have you checked your wp-config.php file? does it have your live site’s database information?

      Administrateur

  12. Aliesha

    I had 4 sites give a 127.0.0.1 « Cannot connect to server » message & I also had no access to admin. I went through troubleshooting, & nothing helped. So, I contacted my web-hosting service, Bluehost, to inquire whether the MySQL server was responsive. The tech told me to login to my control panel’s File Manager, select « Show hidden files, » and then to go inside my root directory for each domain & rename my .htaccess file to .htaccess.old . He said he guessed that a plugin added code to my .htaccess file, causing my wp-admin to redirect to an IP address. It worked. :)

    • WPBeginner Support

      Glad that it worked. However, you should find the plugin responsible for that and delete it.

      Administrateur

  13. Erik de Vries

    Just got this error on my own website. wp-config.php was allright. PhpMyAdmin could load the database. When trying to open the wp_options table PhpMyAdmin said the table must be repaired. Using the repair function in PhpMyAdmin fixed the table, reporting one row had been removed (not saying which one). No clue as to what caused this.
    Thanks for the article, helped me debug the error.

  14. Ben

    Just got this problem, checked db through host cPanel and admin user seems to have been removed from database assuming that is why wp cannot connect. Problem is my ftp also seems to have been knocked out so i am unable to apply any solutions! sub-domain seems to still be working. It’s difficult to imagine this as being anything other than malicious!

  15. Zimbrul

    I just got this problem with one of my sites and fixing the database from wp-config.php did not work. I fixed it by upgrading to WordPress 3.6.1 in cPanel (Softaculous).

  16. Kyra Dawson

    Thank you guys! Great How To article!

  17. Ike

    Today, for some reason my site is facing the database connection issue.
    • Confirmed my database access is working via testconnection.php.
    • Changed the salt keys with new ones.
    • Defined the proper site URLs to ‘WP_HOME’ and ‘WP_SITEURL’
    • No issue with server slowness as my other websites in other root directories are working.

    I’m guessing it may be a plugin recently added?
    How do you properly uninstall a plugin if you can’t pull up both wordpress root and wp-admin directories in the browser?

    Thanks in advanced.

  18. Anudeep

    Thanks a lot for such a good article!
    My problem was a bit different. I had this issue because of ‘clicky analytics’ plugin.
    I almost went mad as i didnt have any idea of what the problem could be. Finally after lot of trial and error i figured out that it was a plugin interference.

  19. Giorgos

    Thanks for the post
    Is work to me

  20. Naman Agrawal

    Huh! sir you deserve an award.
    It just worked for me. I was having this problem from last one month and you just served with this.
    Thank you very much :)

  21. Roeland Sanctorum

    Problem occured when requesting new password and didn’t realise this was going to create a db problem. Fortunately I found your comments and guidelines. Problem solved in 3 minutes.
    Thanks again (now I’ve subscribed to your weekly email)

  22. Tamela

    My problem happened when I moved the site to a new hosting. I’d altered the config file to match my new database, username & password. But nothing worked.

    Your tip about checking the WP-admin page did the trick. It told me something was wrong with the username. I went into c-panel and realized I hadn’t tied the user to the database. Two seconds later, all was good!

    You potentially saved me hours of testing the wrong things! Thanks!

  23. Stu Farrimond

    I want to give you a big kiss.

    VERY useful.

    However, my issue seemed a little odd – and it might help someone else:

    This morning our domain produced error:

    Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 30720 bytes) in /home/gurumaga/public_html/wp-admin/includes/class-wp-list-table.php on line 384

    I tried to increase PHP memory allocation.

    Added to wp-settings (in root folder):
    define(‘WP_MAX_MEMORY_LIMIT’, ‘256M’);
    resulted in:
    ‘Error establishing a database connection’

    Removed line and added lower limit:
    define(‘WP_MEMORY_LIMIT’, ’64M’);
    resulted in:
    ‘Error establishing a database connection’

    Removed all changes in wp-settings.php now as original.
    ‘Error establishing a database connection’ persisted (for 5 – 10 mins)

    Before reverting to the original error:
    Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 30720 bytes) in /home/gurumaga/public_html/wp-admin/includes/class-wp-list-table.php on line 384

    I increased the PHP memory limit to: define(‘WP_MEMORY_LIMIT’, ’64M’); again
    Then ran the database repair as you advised.

    Although no database errors were identified, the site is now back up and running.

    Odd – I’m not sure if you or anyone else can make sense of it??

  24. Donatus

    Thank you so much, i have repair my own and is working perfectly. my site is back

  25. Michael

    Embarrassed… I tried everything in this blog and was double checking everything…
    It never occurred to me that I’d typo’ed when entering the password.

    Doh! So, here’s a +! for double checking the basics ;)

  26. Shaqinah

    Hi, I made the mistake of changing the home url, initially it was http://shaneynayguns.com/wordpress and the site url was: http://shaneynayguns.com/wordpress too. I then changed the site url to http://shaneynayguns.com (thinking that that will make my site go live, as you can tell I’m an absolute idiot at this). Nothing happened, so genius here, changed the home url to shaneynayguns.com. That’s when things start to go awry: I couldn’t log in to wp-admin anymore and going to .com/wordpress redirects me to an error page. (shaneynayguns.com remain unchanged and directs to a landing page) I then went on to a forum and followed the exact instructions which were:
    1. go to phpmyadmin
    2. go to the correct database
    3. browse wp_option
    4. edit site url (I changed it to .com/wordpress)
    Apparently based on everyone’s comments, it worked for all of them… except me! shaneynayguns.com/wordpress now redirects to a page with « error establishing a database connection »! It’s driving me mental! I was hoping if any of you could help me with this. As is obvious, I have not a clue when it comes to web jargon so I would really appreciate a simplified solution. Yes I’m an idiot, and I terribly need help! (F.Y.I: I host on godaddy)
    Thanks in advance!

      • Anderson Tagata

        Hey, this worked for me. My wordpress website is on Godaddy and i was trying to put inside of subdirectory. now it works. Just after this, show up some database upgrade screen then everything is fine. also, i took out these defines above and still working. thanks.

  27. Zac

    Thanks heaps for your info guide, helped me fix my problem.
    To let you know my resolve, I could not see a typo in the wp-config.php but decided to delete my Database and linked Username. I then created new ones and manually updated the new data into the wp-config and boom straight in. One thing to note is the database and username were originally the same name, so not sure if that was an issue as its a new site.

  28. Seth

    My website is down and I keep getting « Error establishing database connection » message.
    I checked my WP-Config.php page and it looks fine on the inside, but when I preview it, the page says this

    Warning: require_once(reddoorplayhouse.com/open/wp-settings.php) [function.require-once]: failed to open stream: No such file or directory in /hermes/waloraweb096/b619/moo.reddoor1/wp-config.php on line 95

    Fatal error: require_once() [function.require]: Failed opening required ‘reddoorplayhouse.com/open/wp-settings.php’ (include_path=’.:/usr/local/lib/php-5.2.17/lib/php’) in /hermes/waloraweb096/b619/moo.reddoor1/wp-config.php on line 95

    What does that mean. And what can I do? Thanks for your help.

  29. Michael Tidwell

    This is a frustrating problem that has been happening multiple times to a few of my sites over the past few weeks. I can fix it easily enough by replacing the Unique Keys and Salts in my wp-config.php file (grabbing new ones at: https://api.wordpress.org/secret-key/1.1/salt), but then days later I have to replace them again… so while I can fix the symptom, I’m still trying to determine why this keeps happening at http://brioagency.com

    • Editorial Staff

      This can be caused by a plugin that you have if it is messing with your settings.

      Administrateur

  30. manesh

    Thanks a lot man, repairing the database fixed my issue!

  31. Andrew Stark

    Hi

    Just thought I’d thank you for helping me fix a site.

    Changing localhost to the database IP address fixed my issue.

    Thanks

    Andrew

  32. Madhurie Singh

    I had made copies of the files and saved them on the server.

    So when today the database connection error occured, I relaized, I had changed user, , pwd, database access but nothing worked.

    So renamed the current wp-config.php as wp-configold.php
    and copied the wp-config.php from the archive and pasted as wp-config.php.

    Voila it works.

  33. Michael Stelly

    Forgot that the database is « local » to the application. I used the site URL by mistake. Switched DB_HOST to ‘localhost’ and all is golden.

    Thanks for the blog! +1

  34. Ben

    You know sometimes you just find the perfect resource and it answers all your questions. I tip people for pouring me a cup of coffee. I wish it was super easy to just put a buck or two in the wpbeginner tip jar right now, but I guess a thanks will have to do.

    • Editorial Staff

      Thanks Ben. Its always our pleasure to help. The best way to thank us is by spreading kind words about our site or by simply sharing this article on twitter, facebook, etc :)

      Administrateur

  35. jAMIE

    WP Beginner is just awesome & so is Syed! I don’t know how many times my search results have let me to your site and each time, I’ve learned something really helpful, useful, & practical.

    This time, with my database connection error issue, I just had to clear my browser’s cache. FML Anyways, that was the advice that I got after contacting my host. It seems to have worked & hopefully that’s all it takes! How to prevent it from happening again is above me.

  36. Mibo

    All I have to say: « THANK YOU! » :-) your post fixed my issues and spared me a couple of hours of work.

  37. Fre

    For me the issue was solved by properly setting “siteurl” and “home” in wp_options table did the trick for me, I could log into my admin and change everything!

    One day I’ll buy you a cookie!!

  38. Julie Anderson

    I have a big problem… i did not set the site up and do not have axxess to the php or any files. i was trying to add pages and the next time i visited the site there was the error. Do i need to get to the admin initiator etc, is there no other way into the site?

  39. Stephen Doxsee

    I get this error intermittently. Perhaps I don’t have enough resources on my amazon ec2 free tier instance. I’ve had the problem 3 times in the last week but have been able to solve it each time by restarting the database server.
    Thanks for the post

  40. udumbuke

    For me issue was solved by properly setting « siteurl » and « home » in wp_options table

    • Mana

      Thank you so much, Udumbuke. This was exactly the step I forgot in moving my site to a new host. I’m so glad I can stop headaching over this! And great guide altogether on this site.

  41. Joyce Keller

    This error happened to me because I wanted to back up my database and could not remember the password. I changed the password in GoDaddy – but this didn’t change it in the wp-config.php! Once I changed it in wp-config, everything worked okay again.

    THANK YOU FOR SUCH A COMPREHENSIVE SOLUTION!!! And a truly useful site. Kudos!

  42. JD

    In step review of wp-config.php you have to consider the user name and password that is there in the file, the user may not exist in the database (mysql), the password has changed so check if there is the user. In case the user does not exist in the database create it, assign the password found in wp-config.php and provide permits for administration of the database (DBA).

    This happened to me to restore my wordpress.

    • Oliver Wieland

      Thanks dude! Restored my database and all i needed to do then was reassign the correct user with the correct database in cpanel.

  43. Pat Walsh

    Hi guys, thanks for this info.
    Helped me to fix a problem with a WordPress site I created.
    It had been happily running for over a month when it started having the « Error Establishing a Database Connection » error.

    Finally fixed it by changing DB_HOST to use the full host name rather than the ‘localhost’ that had been in there before.

    I don’t know why it worked initially and then stopped working. But its working now…
    Cheers,
    Pat Walsh

    • Forma

      Having the same connection to DB problem, and after reading comments, I decided to change the wp.config file refrence to my actual host to localhost and for some reason that fixed it. So my solution was the opposite to the one above. Just a shot in the dark…

  44. arman

    it is indeed helpful for me as i m facing this problem currently… thanks for this great article..

  45. Arifur Rahman

    I’m getting this issue temporary at my site just for few seconds.
    how can I be free from this?
    Please help!

    • Editorial Staff

      Find the root cause. It can be caused by a plugin. Or simply you need to upgrade your hosting plan if you are getting tons of traffic.

      Administrateur

      • Arifur Rahman

        Thank you,
        I already upgrade my hosting plan from basic to Pro.
        But still same as before.
        I using Adminimize, AG Custom Admin, Akismet, BuddyPress Template Pack, Display widgets, Fast Secure Contact Form, Google XML Sitemaps, Jetpack by WordPress.com, Page Views Count, Polldaddy Polls & Ratings, User Switching, Better WP Security, BuddyPress, Hotfix, W3 Total Cache, wordPress Importer and WordPress SEO.
        Which one is making problem??
        Have you any Idea?

  46. Eduardo Capanema

    If you have all the info in the config file correct and is still having the problem, check to see if you have any spam prevention plugin active such as Fail2Ban. I found that it was causing the database problem. I believe it happens cause when you’re editing the wordpress via wp-admin, you make too many sequence requests to the apache it triggers the Fail2Ban service for www-data user. Try uninstalling Fail2Ban or any other spam controller. Then, restart both mysql server and apache to get hid of the Error message.

    I hope this helps.
    b

  47. Stefano

    Thank you guys. Problem solved. Very good post

Laisser une réponse

Merci d'avoir choisi de laisser un commentaire. Veuillez garder à l'esprit que tous les commentaires sont modérés selon notre politique de commentaires, et votre adresse e-mail ne sera PAS publiée. Veuillez NE PAS utiliser de mots-clés dans le champ du nom. Ayons une conversation personnelle et significative.