'Testing a custom Wordpress theme with a different, existing database

I'm designing a blog test theme for a client, and before switching over to this theme, I need to tweak the design to accomodate his current content (spacing, sizing, etc.). I'm trying to import their database into my test theme's database to test, but I'm getting an error: "Cannot establish database connection". I am testing from my own domain/server, and I used HostGator's Fantastico Deluxe and PhpMyAdmin to create the blog and upload the databases. All materials have been backed up.

Here's my process:

  • Dropped all tables from the test theme's db
  • Imported client's existing db into the test theme's db
  • Replaced the test theme's wp-config.php file with existing db's wp-config.php info (mainly db_user and db_password)

What am I missing in order to make the client's existing database display correctly with this test theme?

Thanks for your time.



Solution 1:[1]

check for spacing before and end of the database name in your wp-config.php on root of your website, host name user name and password(mysql default is 'root' and password is '' change this with your creadantials)

Solution 2:[2]

Make sure that in your cPanel / Plesk account, you have added the name of Database, the User and Password. Furthermore, you should connect the user with the database you have already created and give to this user all the privilages. So for example, inside your client's wp-config.php file if you have:

define('DB_NAME', 'database_name');
define('DB_USER', 'database_user_name');
define('DB_PASSWORD', 'user_password');

youu should have all these created in your server account

Thus if your are in cPanel account go to "MySQL® Databases" create all the above and you will be ready to go!

Careful though, sometimes Mysql has already a prefix at the database name. Thus, you may need to change the define variables inside wp-config.php file

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user2385712
Solution 2 Kiriakos Grhgoriadhs