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. cgjam

    had this happen to me when trying to install word press, didnt realise i hadn’t actually enabled user privileges! thanks for this helpful article

  3. Moogie1947

    Just had this happen after I backed up my files and had set up a password to access and backup my database before I upgraded.
    Thanks for your site realised that I had accidentally replaced the autogenerated password (as I didn’t know it existed) . So I found it in the config.php file in my backup set and reset it in the admin panel on my host’s site. All now OK.
    Can’t thank you enough for a brilliant article.

  4. ValentinaMercenaro

    I’ve tried them all! Eventually I solved by creating a
    different DB Username in my host cpanel (giving it all the privileges of
    course) and also changing the DB Host to my server IP in the wp-config.php file.

    I’ve got no clue why that would solve the issue but perhaps
    it could be that the DB Name and DB Username cannot have the same name. (You may think: « duh! Of course not!!! », well, my host’s « DB Creation Wizard » had auto generated the two fields and, believe it or not, it wouldn’t let me change it at the beginning). I had to create a new user
    separately later on to solve the issue.

    Thanks for this great post. x

  5. bfadmin1

    You’re the best ….
    I didnt know that changing the db password would drop the database connection to wordpress ….
    Solution 2 was brilliant ……. 2 min max.
    Thanks alot!!!

  6. needhelpquik!

    hello…i am getting this error. it just happened out of the blue today! nothing was changed other than some text on a page. i logged out. now i got the error.

    in one of the paragraphs you state: « First thing you should do is to make sure that you are getting the same
    error on both the front-end of the site, and the back-end of the site
    (wp-admin). If the error message is the same on both pages “Error
    establishing a database connection”, then proceed onto the next step. » what is the next step? i get the error on both sides.
    this was confusing to me. sorry. so what is the next step so i can try to figure out how to fix this!
    thanks for your help!

  7. PeterBestel

    This error happened to one of my membership sites, except when you logged in, the site looked and acted normally.

    After following the usual routes, including changing the database user and accusing the theme of being the culprit, I discovered an extra « ?> » at the end of the wp-config.php file. Once I deleted that everything worked.

    I have no idea how that ended up there. Hours of frustration sorted by deleting two characters!!

  8. Ed Luvables

    This worked perfectly, I forgot to change my password in the config file. Thanks!

  9. George Stroud

    With this problem I found that it was a database corruption but that it resulted in my not being able to access the WordPress repair tool – however, I could effect a repair by using the mySQL section in my hosts control panel (cPanel) and then the site came straight back up.

  10. Jenerwin

    just encountered this type of error..and i be able to fixed this through database optimize and repair..i like this post..thumbs up..

  11. Carrie Case

    I had the Permalinks set to Post Name. I switched it back to Default and the error went away and my pages re-appeared. I then switched back to Post Name because I prefer this setting, and it still worked. Good to go. Only took several hours to figure that crap out. Lol.

  12. Joninashby

    Saved my life – changed the database password within the hosting control panel, had no idea I had to update it in wp-config. Hours of stress avoided – thanks!

  13. K.C. Bateman

    thank you

    This was very helpful!

  14. Ayo Akinbode

    It worked! tnx so much

  15. BillR

    I had this issue today.
    Server had crashed last night and was attended to fairly quickly when the issue was known.
    All worked for a while but today WordPress couldn’t make a connection to the database.
    The Simple Machines Forum database was working ok and the forum would load.
    What I did was:
    1. Create a new database user
    2. Assigned that user to the WP database with full privileges.
    3. Updated WP_config to use that user

    After that all was good.

    Seems that after a server issue the WordPress user privileges can become corrupt or changed even though the user is shown with full privileges.

    Thanks for this post. It pointed me in the right direction.

    • Alex

      Thank you very much!… hours and hours seeking the answer and your’s worked just fine!…

    • Chris

      This worked for me as well. Very strange.

  16. Enhow

    Hi! I having constantly this issue, I go to the webpage and it shows this error, but then I refresh some minutes later and the error it’s gone. It stopped happening so I even forgot about it. But today I asked my work partners (4 people) to enter the site at practically the same time to see the new mobile appearance and some got the error and others didn’t (it wasn’t exactly at the same time since I asked to do it in their phones and everyone had different speed) this concerns me a lot. I read you told someone else who also had this issue but it fixed by itself that it was because of his server. Should I call my server and ask what’s going on? Or is there a chance I did something wrong? Almost everyday it’s weird and it just go away. Thanks!

    • WPBeginner Support

      It seems like your database server is not working properly. Please contact your web host.

      Administrateur

  17. Mike

    Thank you! Edited the .php file and fixed my problem. Awesome.

  18. Terry

    Sorry guys,but for a real beginner your information appears to assume a greater knowledge on how to do stuff than perhaps some of us have.It’s ok to say,check this or that, but when we have no idea how to get there, it is not much help.I know you are saying that we should not be here if the tech. level is not there, but that does not help.One can follow a more step by step procedure but perhaps that is asking too much.Thanks.

    • WPBeginner Support

      We understand, and we are sorry that you didn’t find this information easy. Please let us know which part you are having trouble with and we will try to explain it more.

      Administrateur

  19. Henri

    Thanks – Your article helped me to fix the problem in minutes!

  20. Chuck

    Last night my Centos server crashed and when it came back up I had the error.

    What worked for me was to rename the file /var/lib/mysql/mysql.sock, start the mysql service with service mysqld start, shutdown the server with shutdown -h now, then bring the server back up.

    Basically, the crash had locked up MySql so it thought it was running when it really wasn’t.

  21. Bart

    Thank you very much!

    In my case I fixed it by

    1) deleting the current user that was connected to my database
    2) creating a NEW user with all privileges
    3) adding this user to the database
    4) refreshing my details in config.php (user and password)
    5) refresh my site (F5)

    Furthermore, although I hadn’t changed anything about this, when I reloaded my WP admin page, a Fatal error occured which told me that the Facebook plugin was creating some sort of memory exhaustion. I disabled the plugin by renaming it in wp-content/plugins and got rid of my problem.

    This, by the way, also solved some display issues on my homepage.

    Hope this feedback helps and again, thank you very much for sharing this article!

    Bart

    • lubna

      I cant log i to my wp after successful installation of db

  22. Ruthie

    When I went to login to my company’s dev site this morning, I got this message (on the back end and on the front end), but 10 minutes later I refreshed the page and it wasn’t a problem anymore. On the one hand, I’m glad it resolved itself, but on the other hand, I’d really like to know why it happened and how it got fixed so it doesn’t happen again. Any ideas?

    • WPBeginner Support

      It is possible that the database server was down at the time you got this error. The issue resolved when the database server came back online again.

      Administrateur

  23. Derek Smith

    I am having a database error that I need help with. I bought 40 WP sites and transferred them from one host to another (GoDaddy). I made the mistake of switching some content on the sites before switching the DNS. I switched all of the domains last night to match the DNS of Godaddy, not I am getting database error problems with all of the sites that I worked on.

    I’m kind of a newbie on the backend side, but I’m thinking that changing the files and then pointing the DNS after this somehow messed everything up, this is the only thing that I could come up with since the sites I didn’t touch still work. Thanks

    • WPBeginner Support

      First you should have backedup your old databases using phpMyAdmin and then import them to your new webhost’s database server using phpMyAdmin. You should then change your DNS settings to point to your new web host. After that you need to edit wp-config file on all your sites, change the database name, password, host, settings to match your new databases.

      Administrateur

      • Derek Smith

        What do I do to fix it now that it is at this point? All the DNS settings are changed and I keep getting the error messages. Is there a way to go back and install the original files ?

  24. Tony

    Hi there…
    I’ve been working with a local install for a while now and wanted to change the url of my local install to something else, so I went ahead and changed quite a few times my wp-config database name, my mamp settings of the database in « wp-options »..plus some others I don’t know remember. This resulted in « error establishing database connection ». I troubleshooted for a whole day, (returning back to the same nightmare I got when I first installed mamp and wordpress locally). I changed everything back the way it was to no avail, making me feel soooo frustrated and stupid again…! So, I read this article to the end and where it says « siteurl » solution in the « Solutions that worked for others » section and went back in phpmyadmin to check this…surely enough…in the « wp-options » of the particular database, in the « site url » field, it had the name of my database, (which I had stupidly changed previously without realising its impact), I also checked it against other databases I could access with no problems and the field indeed said, « siteurl » instead of the actual db name!
    I changed it immediately and phewww….got my database back and working and logging in with no problems..!!
    People, if you did something similar, check this first…it surely made me feel stupid…at least I have another troubleshooting trick up my sleeve now…thank you for your input..!

  25. Thouhedul Islam

    Well, thanks for details. But I think, it is very simple. Don’t take it complicated like you. Just open wp-config.php and change the database username and password. Hope it will be fix.

  26. Bamanya Brian

    Thanks man..i followed all thru and now my site is up..Godbless

  27. Tamas

    Hello,
    Thanks for this description.
    I just moved my site from BlueHost to DreamHost.
    When going to my site I get an EMPTY (really empty, white) page. Nothing else.
    However, when I go to wp-admin… « Error establishing a database connection » is displayed.

    I can log in into the MySQL (going to msql.remete.org) and it works.

    All four parameters in wp-config seem to be oké, as well:
    /** The name of the database for WordPress */
    define(‘DB_NAME’,  »);
    /** MySQL database username */
    define(‘DB_USER’,  »);
    /** MySQL database password */
    define(‘DB_PASSWORD’,  »);
    /** MySQL hostname */
    define(‘DB_HOST’,  »);
    Here I had replaced the « localhost » by the « msql.remete.org », as it should be with DreamHost.

    My site is remete.org.

    I moved already several WP sites … and some worked well, some had the white page at the root, however, this is the first and only one with « Error establishing a database connection » error.

    How may I make the DB connection work?
    How can the root made work, as well (instead of the white page)?

    I would really appreciate your help.

    Thanks a lot,

    Tamas from Budapest

  28. d4drdave

    Ace post, worked a treat ;)

  29. Shlomi

    for a multisite deployment, you also need to check the table wp_blogs and make sure the correct URL appears there, otherwise wordpress will say « error-establishing-a-database-connection »

    • Matt

      DING DING! I had pulled down a copy of production data and was suddenly getting this error with a multisite instance. Updated the « domain » column in wp_blogs and it works again. Thanks for pointing it out!

  30. Olga

    Thank you for producing this quality post. Your instruction worked perfectly! and saved me lots of hassle :)

  31. Bulbul

    Thanks! it solved my problem in few minutes..

  32. Alex

    Hey man. I just wanted to thank you for this GOOD post. It didn’t work and I didn’t know why.
    I read your blog and followed everything and now it works again.. after 11 HOURS of work.

    This is a sign of appreciation.. If you were here I’d get you a huge beer. Thanks so much for your clear help!

    Alex

  33. Travis

    Oh my goodness. Typically posts like these usually don’t pan out for me after following directions… but you sir have saved the day here. Thank you!

  34. Tish

    Thank you so much for this! I definitely thought I had lost my site completely until I followed this. My only hangup was that I had no idea where to find the wp-config.php file without being able to get into wordpress. I eventually found my file manager through my hosting, but it took me a while to figure that part out. Keep the great info coming!

    • WPBeginner Support

      Zewdu this could happen when your file permissions are not properly set, or some configuration issue on your hosts end. Please contact your web host.

      Administrateur

  35. Michael

    OR….

    *IF* you were messing around in the editor with any of your .php pages/code in the editor and your copy/paste back to the original did not work on this database connection error… the work-around is to then copy/paste back via FTP to the exact folder of the .php file rewriting over the edited one and this will for sure work to get your site to show back up online again.

  36. superfunkie

    Hi! Im facing the same problem with the wordpress. I did copy and paste the testconnection.php and it showed « Access Denied ». But when I edited the line – « mysql_connect » to « mysqli_connect » database was connected successfully. How do I implement « mysqli_connect » in the wordpress config file?

    • WPBeginner Support

      Superfunkie please check your php version if it is PHP 5.5 then contact your webhost and let them know about this error.

      Administrateur

  37. Aaqil Mahmood

    I am seeing « a secure data connection could not be established » on android browsers for my site

    , only when reading posts not on homepage.

  38. marcel

    Hi there,
    I am desperately trying to launch a new install of WordPress with MAMP, both Apache en MySQL give green lights, but when starting up in the browser I get the « Error establishing a database connection » message.
    I am relatively new and most of the options above seem rather advanced, and for websites that have already been working, is there a simple way to tackle this for new installations of WordPress?

    WordPress was supposed to be not too difficult to install….

    Thanks in advance!

    • WPBeginner Support

      marcel open the wp-config.php file in your WordPress install folder. And check your database username and password. Usually on fresh install of MAMP database username should be root and password should be left blank.

      Administrateur

  39. patel sumit

    very help full thanks

  40. Gautam Sharma

    i am a newbie & my site data access via filezilla, Please tell how to test connection as i have not seen any phpmy admin in hosting control panel.

    • WPBeginner Support

      If your web host is using cPanel you will see phpMyAdmin under database section. For other hosting control panels, you can ask your web host about it.

      Administrateur

  41. Jen Barnes

    Pardon my seemingly dumb question, but what do I put in for « root » in the MySql test?

    $link = mysql_connect(‘localhost’, ‘root’, ‘Q3dDZE3PiUpQ’);

    Thanks!

    • WPBeginner Support

      replace root with your MySQL username (unless your MySQL username is already root then don’t change it) and then your password. Let’s assume your mysql host is localhost, username is jenbarnes and password is Q3dDZE3PiUpQ then you would use it like this

      $link = mysql_connect('localhost', 'jenbarnes', 'Q3dDZE3PiUpQ' );

      Administrateur

  42. lee getty

    Thanks dude you saved my website

  43. Kasper

    Hey, I can’t launch my site as wp-admin or just visit the site?
    what to do? It’s all my 4 domains there’s been down by this error (below)
    « Error establishing a database connection »
    Please help me!

    – Kasper

  44. Faysal Shahi

    Bro, add Google translator in this blog. I need this post in Bengali.

  45. Peter

    Thanks mate !

    Helped a lot, keep up the good work :D

  46. Asif

    Oh! thank you guys! I almost had a heart attack.
    This was the first time I was backing up my data (so that my website doesnt crash or even if it did I could recover it) logged in to PHPadmin panel changed the password caz the original one was auto generated. logged in and backed up. relieved I went back to my website and boom! these big letters: Error Establishing a Database Connection
    man, you can understand I flatlined for a few seconds..

    Anyway thanks alot!!

  47. onel

    Thank you so much!!! It works!!!

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.