[Resolved] Error establishing a database connection
How to avoid the dreaded “Error establishing a database connection” when “cloning” a site to your local computer.
I have a WP site hosted on inMotionHosting.
I wanted to create a local copy on my computer to use for troubleshooting and generally messing around.
I FTP-ed to my IMH site and downloaded all the files to a folder in the Sites directory of my iMac.
I exported my SQL database to my Downloads folder.
I had difficulty importing the data into phpMyAdmin. Seems as if the exported file wanted a specific database in which to import the data. (I guess that’s pretty obvious, but sometimes I have difficulty with undocumented stuff like that.).
Anyhow, I created a database with the same name as the database I created @ IMH. (I’m beginning to believe it MIGHT have been able to be named anything.) But once I did that and told the export file to use that database, the import worked like a champ.
Fire up the browser, type “localhost” in the URL window – (I have MAMP configured to point to a folder in which I have three website installations set up) – select the folder for my site and BAM – “Error connecting to database.” RATS!
DELETED wp-config file – figured I needed to recreate it.
COPIED wp-config-sample to “root” folder (figured THAT out when I tried to recreate the wp-config file and was told that it needed the wp-config-sample file.)
REFRESHED browser – continued creating wp-config
ENTERED username and password information from the old wp-config file
BAM – “Error connecting to database” – RATS!!
CREATED a user in the database with same username and password as in the IMH site
NO DEAL – didn’t work
Finally just used username = root and password = root (defaults when setting up DB) and…
BAM – it worked.
I was prompted to “Click to install”, but terminated the operation since everything was already installed.
Site is up and running just fine.
Wondering what would happen if I deleted the user I created in the DB, I did so and the site still worked.
Evidently you have to create a new database
Import your data from the other site
Delete wp-config to force the creation of the new wp config file (you probably can manually edit it, though).
Make sure wp-config-sample is in the root directory
Start up WP so it starts the creation of a new wp-config file
Enter in the DB username and password information when prompted (if you are using defaults, then it’s “root”/”root” – as in my example above)
Stop the install process after you’ve connected to the DB
Hope that helps someone else if you want to do the same thing I did.
- The topic ‘[Resolved] Error establishing a database connection’ is closed to new replies.