admin管理员组

文章数量:1289542

Here's my setup. I have a Multisite instance running at , and I want to do development and staging. Moving an existing Multisite instance of WP onto localhost is a nightmare, so I'm going to do dev on a staging location instead.

I set up to point to the /public_html/staging/ directory of the hosting account, and copied all of the WP files from my root into the /staging/ directory. I also copied the database files (SQL dump, imported the tables into a new database), and changed the wp-config.php file to point to the new database.

After running SQL to change the database records, I also change this one line in the wp-config.php file:

/** Turning on WordPress MU, new in 3.0 */
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false );
$base = '/';
define( 'DOMAIN_CURRENT_SITE', 'example' ); // <- I change this line
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

Changed to:

define( 'DOMAIN_CURRENT_SITE', 'staging.example' ); // <- now changed

When I load up , I get... Error establishing database connection!

I've checked and triple checked the username and password, made sure that the user has all privileges on the new staging database, and I've left the DBHOST as 'localhost' (although changing it to staging.example didn't help, either).

Why would the database connection fail? Anyone? (Thanks for your help in advance.)

NB: is working fine running on very similar db connection settings, just with a different database, so it's not an issue with the database server being down.

Here's my setup. I have a Multisite instance running at http://example, and I want to do development and staging. Moving an existing Multisite instance of WP onto localhost is a nightmare, so I'm going to do dev on a staging location instead.

I set up http://staging.example to point to the /public_html/staging/ directory of the hosting account, and copied all of the WP files from my root into the /staging/ directory. I also copied the database files (SQL dump, imported the tables into a new database), and changed the wp-config.php file to point to the new database.

After running SQL to change the database records, I also change this one line in the wp-config.php file:

/** Turning on WordPress MU, new in 3.0 */
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false );
$base = '/';
define( 'DOMAIN_CURRENT_SITE', 'example' ); // <- I change this line
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

Changed to:

define( 'DOMAIN_CURRENT_SITE', 'staging.example' ); // <- now changed

When I load up http://staging.example, I get... Error establishing database connection!

I've checked and triple checked the username and password, made sure that the user has all privileges on the new staging database, and I've left the DBHOST as 'localhost' (although changing it to staging.example didn't help, either).

Why would the database connection fail? Anyone? (Thanks for your help in advance.)

NB: http://example is working fine running on very similar db connection settings, just with a different database, so it's not an issue with the database server being down.

Share Improve this question asked Jul 18, 2011 at 12:53 Jason RhodesJason Rhodes 5271 gold badge4 silver badges16 bronze badges 3
  • Hmm. Nobody, huh? It's a weird error, for sure. – Jason Rhodes Commented Jul 18, 2011 at 21:16
  • I have the same error when trying to do Wordpress Network migration in-place - no host moved – Mikko Ohtamaa Commented Aug 22, 2011 at 7:29
  • Ok. I tracked down various failure modes and made a blog post of them: opensourcehacker/2011/08/22/… – Mikko Ohtamaa Commented Aug 22, 2011 at 13:44
Add a comment  | 

4 Answers 4

Reset to default 3

One thought - when I go to www.example/staging/wp-admin it automatically redirects me to www.example/wp-admin

Could the redirect from staging.example to example/staging be conflicting with the existing install?

UPDATE: looks like it could be related to .htaccess issues and complicated domain references in the database

From the WP Codex:

Moving WordPress Multisite

Multisite is far more complicated to move, as the database itself has multiple references to the server name as well as the folder locations.

The best way to move Multisite is to move the files, edit the .htaccess and wp-config.php (if the folder name containing Multisite changed), and then manually edit the database. Search for all instances of your domain name, and change them as needed. This step cannot yet be easily automated. If you're moving Multisite from one folder to another, you will need to make sure you edit the wp_blogs entries to change the folder name correctly.

I solved it & it worked :)

In wp_blogs table ,

Old structure was

Domain : localhost/smart_facility_linux
Path : /

But i changed it to to make it work as follows:

For root site:

Domain : localhost
Path : /smart_facility_linux/

For sub site 1 (any subsite under main site ,I just gave example) :

Domain : localhost
Path : /smart_facility_linux/subsite1/

There is really only one way to do an easy transfer of domain or host that I have found. It works flawlessly for me on single and multisite installations.

  1. Export your database to a .sql file. ( I use PHPMyAdmin for this )
  2. Create a new copy of the file to be edited with a slightly different name.
  3. Open the file in you preferred text editor> ( gedit for example )
  4. Run a find/replace on the domain AND absolute path ( /home/username/public_html/ to /home/username/public_html/ ) from production to dev.
  5. Save the file.
  6. Copy the entire installation to your development directory.
  7. Add the following line to your wp-config.php file:

    define('RELOCATE',true);

  8. Log in, and save your permalinks settings.

  9. Remove the define rule you put in your wp-config.php.

This worked for me.

  1. zip all files
  2. download database
  3. upload files to the new server
  4. Edit database in any editor (I used Notepad++)
  5. Replace domain with newdomain
  6. upload database to the new server
  7. Login and enjoy!

Note: Remember to change domain name inside config.php. Also, copy the .htaccess file to the new server. This is for basic WordPress Multisite with minimal plugins. Try to take a backup first.

本文标签: databaseDB connection error after copying a WordPress Multisite instance to a second location