• Hi there, I am having trouble setting up a local installation of a live site. I’ve gone through this thread with an identical problem, but not had any luck.

    The live site is hosted on DreamHost. I’ve downloaded the site files via FTP as well as the SQL database. I’m running MAMP locally which was working fine with a clean install of WordPress. I’ve updated wp-config with the database name and used username: root, password: root, host: localhost.

    In MAMP, my ports are set to Web – 80 and MySQL – 3306. Try as I might, when I go to localhost, I get the message: “Error establishing a database connection.” Help is appreciated.

Viewing 13 replies - 1 through 13 (of 13 total)
  • I have the same problem, but I am using WAMPSever 4.52.
    Had no problem prior to WP 4.8 update.

    When trying to access /wp-admin, I get this Error:
    “Error establishing a database connection”

    Also, unable to login to phpMyadmin, will not accept my username & password which (same username & password I always use), I get this Error:
    “Cannot log in to the MySQL server”

    • This reply was modified 7 years, 4 months ago by rbschneider1. Reason: Added info
    Moderator t-p

    (@t-p)

    Side note to @rbschneider1,

    Please do not jump into other topics. As per the Forum Welcome, please post your own topic.

    Moderator t-p

    (@t-p)

    – “Error establishing a database connection” means that there is a problem with the connection to your database
    – a problem with the credentials stored in the wp-config.php file not matching what mysql expects.
    – Try reviewing the following codex for some guidance: https://codex.www.ads-software.com/Common_WordPress_Errors#Error_Establishing_Database_Connection

    For local install, also review:

    https://make.www.ads-software.com/core/handbook/tutorials/installing-wordpress-locally/

    https://codex.www.ads-software.com/Installing_WordPress#Installing_WordPress_on_your_own_Computer

    https://codex.www.ads-software.com/WordPress_Installation_Techniques#Installing_WordPress_Locally

    https://codex.www.ads-software.com/Installing_WordPress

    Sorry, was not trying to jump in on the post, but was attempting to add to it. Next time I will start a new post.

    Thanks for your fast reply, I will look into your suggestions.

    Thread Starter melhopkop

    (@melhopkop)

    Hi @t-p,

    Yes, as I attempted to indicate in the initial post, I’ve already addressed the guidance in the Codex. I’ve read copiously as well as combing through forum and walking through previous advice before starting a new thread requesting help.

    I understand that “Error establishing a database connection” means that there is a problem with the connection to the database. I’ve tried for hours to verify that the info contained in wp-config.php matches the MySQL set up. Obviously, I’m doing something wrong because it’s not actually working.

    Any more specific guidance, unusual things to try, or troubleshooting steps would be appreciated.

    Thanks!

    Hey @melhopkop, as you’ve rightly observed, this error indicates a problem connecting with the database. A few things to help with troubleshooting:

    1. Can you confirm that you have a running MySQL instance on MAMP?

    2. Do you have any other active WordPress sites in your local MAMP environment?

    3. Can you confirm that your MySQL username and password match what you have in config.sys?

    4. Is this database (and its tables) accessible using PhpMyAdmin, or similar?

    5. Is the database imported from the live Dreamhost site?

    6. Are you able to connect to a brand new, fresh database on MAMP?

    You may have tried all the above, but it will be useful to confirm first that you have tried them all

    Best Regards.

    Thread Starter melhopkop

    (@melhopkop)

    Hi CJ! Thanks for your reply.

    1. Yes, I can confirm that I do.

    2. Yes, as part of my troubleshoot, I downloaded and successfully installed a clean version of WordPress, which works fine.

    3. config.sys is a new one to me. Where do I find that? I have been editing wp-config.php. The database name is correct. DB-Host is set to ‘localhost’ (also tried it using 127.0.0.1, with no success). For the user and password, I have tried both ‘root’ ‘root’ as well as the username and password that was used on the live site (since both users exist on my local installation). Neither of these was successful.

    4. Yes, the database is accessible using PhpMyAdmin.

    5. Yes, the database is imported from the live Dreamhost site.

    6. Yes.

    Thanks, for helping me get to the bottom of this. It often ends up being something obvious but after so many hours of trying, fresh insight is appreciated.

    Hi @melhopkop,

    “config.sys”?? I meant “wp-config.php”! Sorry about that.

    I assume that if you point this imported site to one of your other local databases, the site then works fine?

    The database username and password would match your local database details, e.g. “root”, “root”.

    The other thing to perhaps take a look at is the permissions for that particular database (which was imported). Depending on how it was imported, it could still have permissions for the Dreamhost DB user account, which would likely be different from what you have locally.

    • This reply was modified 7 years, 4 months ago by CJ Andrew.
    • This reply was modified 7 years, 4 months ago by CJ Andrew. Reason: added more information for db permissions
    Thread Starter melhopkop

    (@melhopkop)

    “I assume that if you point this imported site to one of your other local databases, the site then works fine?”

    Ooh, that’s a good troubleshooting step I hadn’t tried! Nope, when I point the locally downloaded live site to another database on my computer, it still fails to make the connection. But if I set up the clean install of WP as the active site in MAMP, then that works . . . I’ve tried copying and pasting the first four variables from wp-config from the clean WordPress to my downloaded site just to see if there was a trailing space or errant punctuation but that still hasn’t worked.

    Dion

    (@diondesigns)

    Try changing the host from localhost to localhost:3306 and see if it helps.

    Unfollowing..

    Hi! I had the same problem and finally just resolved.

    If you go to the original https://localhost:8888/MAMP/index.php it will list the following:

    MySQL
    MySQL can be administered with phpMyAdmin.
    To connect to the MySQL server from your own scripts use the following connection parameters:

    Host localhost
    Port 8889
    User root
    Password root
    Example: $link = mysql_connect(‘localhost’, ‘root’, ‘root’);

    Note that my port is listed as 8889.
    In order to properly log in I changed the ‘localhost’ to ‘localhost:8889’ and it worked.
    So find out what port you are using and add to your host name and it should log you in (with all other info the same.)

    Hope this helps!
    xoxo – whit

    Hey @melhopkop,

    Thanks for taking the time to follow through.

    I have to ask, how was the live site downloaded?

    Also, was there an “.htaccess” file that came along with the live site’s files, during the download? If such a file exists, it may have unique settings for the live site, and may need to be removed. WordPress will recreate it if needed.

    At this stage, here’s what I would recommend:

    1) Create a brand new WordPress site with new files
    2) Copy the “wp-content” folder from the downloaded live site onto the new WordPress site
    3) Point the new WordPress site to your downloaded live site database

    That should sort the problem.

    If, however, you still experience trouble at step 3, then it may be necessary to re-import the live database, in which case I would advice that you use something like Migrate DB Pro to sync the databases. But we can cross that bridge if/when we arrive there.

    In any case, let us know how you get on.

    Best Regards

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Error Establishing a Database Connection on Local Server’ is closed to new replies.