We’ve all been there with a WordPress install: “Can’t Establish a Database Connection”.
I made sure that my connection info was correct, and unlike every other PHP app install, I continued to get the error.
Assuming I still managed to get something wrong, I was good sport and used a barebones PHP script to test the connection info. To my surprise, it worked. The problem had to be with WordPress.
After a few hours of experimenting, I found the problem. I had created a test working copy on my public development server; the WordPress install I was using locally at “wp.localmachine.com” moved to “wp.devmachine.com”, and I had simply copied over the same database. The WordPress database references the site URL in several places, and you need to update these URLs in MySQL for your alternate site to work. The easiest way to do this is to dump your database to a .sql file, then find and replace the original domain (“localmachine.com”) with the new one (“devmachine.com”). Then import the resulting .sql file on the new server.
If you’d rather update the new database by hand, I believe you’ll need to change domain references in wp_site, wp_options, and wp_blogs. But be careful, wp_posts and several other areas will have references to your old domain.
4 Comments
pre school academy / #1
October 6, 2011 / 9:11pm:
So cool! Thanks.
electricity saving / #2
October 8, 2011 / 2:03pm:
posts are very nice.
Matt / #3
October 10, 2011 / 9:11am:
I don’t want to get real judgmental, but you both seem kind of like spam. If you are in fact human beings, thank you for the comments!
Anton / #4
April 10, 2012 / 4:03am:
Hello! I have been working as a php freelancer for quite a few years. I use wordpress a lot and as you, I have come across this bug many times…
Anyway nice post!
You can find me in http://www.peopleperhour.com