WordPress.org

Ready to get started?Download WordPress

Forums

Error establishing a database connection (37 posts)

  1. zhrance
    Member
    Posted 6 years ago #

    Dear...

    Well I was very enthusiastic about wordpress and bought the required services I need for wordpress, after transferring all the files to my FTP I get the classic error: Error establishing a database connection. I read the forums and I am 100% I used the right username, password, database name and hostname...

    Please help me, really getting insane at the moment why it doesn't work... (btw checked my mySQL services etc everything is up and running I really don't get it)...

  2. kmessinger
    Volunteer Moderator
    Posted 6 years ago #

    Error establishing a database connection
    This is not a random error. You must have something wrong. Recheck your wp-config.php file and make sure it is uploaded to the server.

    <?php
    // ** MySQL settings ** //
    define('DB_NAME', 'mydatabasename');    // The name of the database
    define('DB_USER', 'username');     // Your MySQL username
    define('DB_PASSWORD', 'password'); // ...and password
    define('DB_HOST', 'localhost');    // 99% chance you won't need to change this value
  3. zhrance
    Member
    Posted 6 years ago #

    Like I said my friend I am 100% sure this is right! checked it around 14 times and also reuploaded the wp-config.php file several times to make sure I didn't make any stupid mistake :(

  4. kelvyn
    Member
    Posted 6 years ago #

    Hi
    I have the same problem. 'My database name' seems straight forward but username gives me a problem because I do not think I was asked for a user name when I setup the mySQl database. My isp says I should use the database name as the user name,
    Kelvyn

  5. powell
    Member
    Posted 6 years ago #

    Hello
    I also have the same problem. Have been in contact with my webhost and they are saying that my database name, username, password and host is qiute right. Still when I am going to install, i get the message that "this page can not be shown" and I have tried to upload all the files many times over. I would be very grateful if someone could be helpful
    //jim

  6. funkster
    Member
    Posted 6 years ago #

    I had this problem and found that switching between 'local host' and the 'actual ip address' can help.

  7. kmessinger
    Volunteer Moderator
    Posted 6 years ago #

    You should be able to log on to your website and check your database name, password, etc. Whatever front-end your host provides should give you access and control of the db thru phpMyAdmin or something like that.

    I am not encouraging you to mess with your database but to confirm yourself the name, password, etc.

  8. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Like I said my friend I am 100% sure this is right!

    And like he said, it is not a random error.

    That error can only happen when:
    a) The web server cannot connect to the database.
    b) The information is not "100% right".

    There really is no alternative answer to give you. Either the database is broken or the information you have put in is incorrect. To be more specific, only the hostname, username, or password can cause this error to be displayed (when the database name is incorrect, it will give you a "Can't select database" error instead).

    If you need your host to fix it, you can tell them that the relevant PHP code to reproduce the problem is basically this:

    <?php
    $host = 'hostname';
    $user = 'username';
    $password = 'password';
    $dbh = @mysql_connect($host, $user, $password);
    if (!$dbh) {
    echo "Error establishing a database connection";
    } else {
    echo "Database connection successful";
    }
    ?>

    That's basically the same thing as what WordPress is attempting to do. If that works, WordPress will work.

  9. kelvyn
    Member
    Posted 6 years ago #

    I changed the local host and get the following

    ?php // **MySQL settings ** // defie('DB_NAME', 'acidreflux'); // The name of the database define('DB_USER', acidreflux); // Your MySQL username define('DB_PASSWORD', 'REMOVED'); // ...and password define('DB_HOST', '209.126.254.221 // 99% chance you won't need to change this value define('DB_CHARSET', 'utf8'); define('DB_COLLATE', ''); // You can have multiple installations in one database if you give each a unique prefix $table_prefix = 'wp_'; // Only numbers, letters, and underscores please! // Change this to localize WordPress. A corresponding MO file for the // chosen language must be installed to wp-content/languages. // For example, install de.mo to wp-content/languages and set WPLANG to 'de' // to enable German language support. define ('WPLANG', ''); /* That's all, stop editing! Happy blogging. */ define('ABSPATH', dirname(__FILE__).'/'); require_once(ABSPATH.'wp-settings.php'); ?>
    Fatal error: Call to undefined function: wp() in /home/domains/acidreflux-and-gerd.com/web/wordpress/wp-blog-header.php on line 18

    How do I fix?

    Kelvyn

  10. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    You broke the file somehow. Start again with a fresh copy of the sample file and use a standard text editor. Notepad will work.

  11. growingthumbs
    Member
    Posted 6 years ago #

    You can also upload wordpress to your host without editing the config.php file. I forgot to do that once and It allowed me to input the database information through my web browser

  12. Tamzette
    Member
    Posted 6 years ago #

    I had the same problem, where the error message says that it can't contact the database server at localhost.
    Any suggestions?

  13. jademoon
    Member
    Posted 6 years ago #

    I had the same problem, but then I changed 'localhost' and everything worked perfectly.
    My host was a series of numbers, but I guess it doesn't has to be.

  14. kmessinger
    Volunteer Moderator
    Posted 6 years ago #

    This message
    "This either means that the username and password information in your wp-config.php file is incorrect or we can't contact the database server at localhost. This could mean your host's database server is down."
    does NOT mean "localhost" is incorrect. There is a "99% chance you won't need to change this value."

    First exclude all other factors like missppelling, to many blank spaces, all other HUMAN errors. 99 times out of a hundred, the error will be operator error.

  15. dbenson9876
    Member
    Posted 6 years ago #

    I have a Linux PHP account hosted by GoDaddy. I was getting the same errors until I changed "localhost" to the hostname listed in my SQL database control panel on GoDaddy. Everything immediately started working perfectly. The entire process took about 15 minutes. Uploading the files was about 5 minutes of that. Hope this helps.

  16. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    That "99%" seems like crap to me. For most hosts, the database server is separate from the webserver. If you are running on a dedicated box, sure, localhost makes sense. But for 99% of the shared hosting, the mysql box will be separate, and it will not be "localhost" for that parameter.

  17. jtilton
    Member
    Posted 6 years ago #

    Stupid me ...I had the same problem. I went back to check everything and found that I had forgotten to save the Username/Password settings. Once I "saved" it everything was fine! Duh!!!

  18. kelvyn
    Member
    Posted 6 years ago #

    Anybody got any idea what wp() in wordpress/wp-blog-header.php should be

  19. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Errr... what? Don't edit the wp-blog-header.php file. It's correct as it is.

  20. kelvyn
    Member
    Posted 6 years ago #

    If its correct why do I get the following:

    Fatal error: Call to undefined function: wp() in /home/domains/acidreflux-and-gerd.com/web/wordpress/wp-blog-header.php on line 18

  21. MartyBLOGs
    Member
    Posted 6 years ago #

    Hey dbenson9876 I have the same type of account with godaddy. Where exactly did you change that "localhost" entry? Some how over the course of the day the error message has changed. Here's what I'm getting now.

    --------------------------

    Internal Server Error

    "The server encountered an internal error or misconfiguration and was unable to complete your request.
    Please contact the server administrator, support@supportwebsite.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

    Apache/1.3.33 Server at martyblogs.com Port 80"

    --------------------------

    Anybody know how to fix this?

    jtilton what username and password settings are you referring to and where did you correct it?

    Thanks.....Martin

  22. rcaffrey
    Member
    Posted 6 years ago #

    Hi Newbie here so always believe I got it wrong (99% right)
    error message is useer name password ok but not able to select database.
    This is what I have in my config

    // ** MySQL settings ** //
    define('DB_NAME', 'mydomainname.com'); //www.mydomainname.com'define('DB_USER', 'username'); //account.webhost.com-username
    define('DB_PASSWORD', 'password'); //www.mydomainname.com-username-password
    define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value
    define('DB_CHARSET', 'utf8');
    define('DB_COLLATE', '');

    Have tried many many variations - where am I going wrong? Please

  23. kmessinger
    Volunteer Moderator
    Posted 6 years ago #

    <?php
    // ** MySQL settings ** //
    define('DB_NAME', 'mydatabasename'); // The name of the database
    define('DB_USER', 'username'); // Your MySQL username
    define('DB_PASSWORD', 'password'); // ...and password
    define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value

    See above. 1.) Your db name is not your domain name. It is the name of your database which is usually like wp-1 or mydb or mydogsname-1 - whatever you named the db. You should be able to go to your website admin and find the db to check the name.
    2.)your user name is just that - just the name you sign in with when you go to your website admin
    3.)your password should be just the password you sign in with when you go to your site admin
    4. leave this alone for now
    define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value
    Delete this
    define('DB_CHARSET', 'utf8');
    define('DB_COLLATE', '');

  24. jackchan
    Member
    Posted 6 years ago #

    I also have a problem .I have been used domaincheck.net windows server .

    <?php
    // ** MySQL settings ** //
    define(DB_HOST','h50mysql.secureserver.net');
    define('DB_NAME', 'username'); // The name of the database
    define('DB_USER', 'username'); // Your MySQL username
    define('DB_PASSWORD', 'password'); // ...and password

    // You can have multiple installations in one database if you give each a unique prefix
    $table_prefix = 'wp_'; // Only numbers, letters, and underscores please!

    // Change this to localize WordPress. A corresponding MO file for the
    // chosen language must be installed to wp-content/languages.
    // For example, install de.mo to wp-content/languages and set WPLANG to 'de'
    // to enable German language support.
    define ('WPLANG', '');

    /* That's all, stop editing! Happy blogging. */

    define('ABSPATH', dirname(__FILE__).'/');
    require_once(ABSPATH.'wp-settings.php');
    ?>

    Anyone can help me??

  25. kelvyn
    Member
    Posted 6 years ago #

    My ISP advises that I have completed wp_config.psp correctly.

    Where do I go from here???

  26. rcaffrey
    Member
    Posted 6 years ago #

    Thank you for your help.
    Gave me the right questions to ask host.
    Contacted my provider who has an auto setup for wordpress and you guys already.
    So cleared my files and used there loader - took 5 minutes.
    So everyone having trouble ask your provider/host for help. (of course some have already done that - sorry).
    Look forward to Bloging with you at http://www.hwhsolutions.com/blog

  27. kelvyn
    Member
    Posted 6 years ago #

    rcaffrey I left a message on your new blog which is waiting for moderation. Do I get a prize for making the first comment.

    my question was which provider are you using?

    Kelvyn

  28. kelvyn
    Member
    Posted 6 years ago #

    Success at last. Thank you

    Kelvyn

  29. obscure
    Member
    Posted 6 years ago #

    Kelvyn,
    Is it now fixed? I noticed that the file output you posted about did in fact have an input error despite your 14 checks ;)

    ?

    php // **MySQL settings ** // defie('DB_NAME', 'acidreflux'); // The name of the database define('DB_USER', acidreflux); // Your MySQL username define('DB_PASSWORD', 'REMOVED'); // ...and password define('DB_HOST', '209.126.254.221 // 99% chance you won't need to change this value define('DB_CHARSET', 'utf8');

    ('DB_USER', acidreflux); is wrong. should have been ('DB_USER', 'acidreflux');

  30. clew
    Member
    Posted 6 years ago #

    so, I appear to be having a similar issue. what makes mine a little different is that mine was working perfectly for about a month and then poof. I get the database connection error. I'm certain I have everything entered correctly in my wp-config.php file (as it was working fine). I checked with my host and they confirm that my DB is working properly. Any help/ideas would be appreciated--including which files I should back up if I have to start over. I don't want to lose what I've already posted.

Topic Closed

This topic has been closed to new replies.

About this Topic