Wordpress Multisite “Error establishing a database connection” in localhost

后端 未结 11 1359
北荒
北荒 2020-12-24 14:04

When attempting to convert WordPress to a Multisite setup, I get the error:

Error establishing a database connection

I\'m using

相关标签:
11条回答
  • 2020-12-24 14:35

    My DOMAIN_CURRENT_SITE in wp-config.php was define('DOMAIN_CURRENT_SITE', 'www.example.com');

    Removing "http://" in wp_blogs -> domain fixed my issue.

    0 讨论(0)
  • 2020-12-24 14:37

    Besides to all said above, if working with multisite environment please check also the following: in the respective subdirectories (/home/subsitename) there exist separate wp-config.php and .htaccess files for each of (sub)sites, so the above mentioned parameters have to be adjusted in all of these files. For example, my main site was working correctly since these files in my /home directory were OK, but when tried to access my sub-sites, I've been receiving database connection error message until I adjusted these files too.

    0 讨论(0)
  • 2020-12-24 14:46

    I had the problem after moving the multisite from a sub directory to the root directory.

    What solved it for me was partly what has been mentioned by Sabin Chirila :

    1. Make sure: DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST in your wp-config.php are really the ones expectected.
    2. As Dima L. mentioned before, define('MULTISITE', true); is expected too.
    3. Change the 'wp_blogs' table's column 'path' to "/" and the DB connection was re-established.

    but I had to change some more things.

    1. In order to be able to view the frontend I also had to change the 'wp_site’ table's column 'path' to "/"
    2. and then (in theme twentyseventeen-child) I had to reconfigure some configuration settings in the backend as they weren't taken into account. But that was simple as the data was still there.
    0 讨论(0)
  • 2020-12-24 14:46

    Here's How I fixed it

    config settings

    define( 'MULTISITE', true );
    define( 'SUBDOMAIN_INSTALL', false );
    define( 'DOMAIN_CURRENT_SITE', 'localhost' );
    define( 'PATH_CURRENT_SITE', '/myblog/' );
    define( 'SITE_ID_CURRENT_SITE', 1 );
    define( 'BLOG_ID_CURRENT_SITE', 1 );
    

    then in the database table (found using phpmyadmin) wp_blogs set the values for your root blog (which should be lie/number 1) to

    domain localhost
    root /myblog/
    

    And finally - reset the sitrurl and homepage in options table (again found using phpmyadmin) to

     http://localhost/myblog/
    
    0 讨论(0)
  • 2020-12-24 14:49

    Inspired by Sabin's answer, I checked wp_blogs and found that the domain value was still pointing to the wrong domain (I was moving a multi-site to a dev server). Running UPDATE wp_blogs SET domain='example.com'; fixed my issue (note that I'm using subfolder multisite, not subdomain - don't blindly run that SQL!)

    0 讨论(0)
提交回复
热议问题