Wordpress Multisite “Error establishing a database connection” in localhost

后端 未结 11 1358
北荒
北荒 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:23

    I had a strange encounter very recently. After setting up a dev server which runs under a different domain and moving a multisite setup to it I got the same error “Error establishing a database connection”. I had checked that all the wp_options tables have the correct domains in the respective settings and that my database connection had the right credentials and would work under normal circumferences.

    I found a way to get a better error reporting. I added an output of the database object in the function dead_db() in functions.php which then showed me that it couldn’t find any blogs for my site in the table wp_blogs. I simply forgot to update the domains for the test server in this table.

    function dead_db() {
      global $wpdb;
    
      echo "<pre>";
      print_r($wpdb);
      echo "</pre>";
    
      wp_load_translations_early();
    

    Hope that helps someone :)

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

    I struggled a long time because of this issue. And finally found a solution.

    You should not add all those settings at once in the wp-config.php file. Follow the exact steps described here: http://codex.wordpress.org/Create_A_Network

    Only add the following code as the first step:

    /* Multisite */
    define( 'WP_ALLOW_MULTISITE', true );
    

    And then refresh your page. After that, in your administration panel go to Tools -> Network Setup and choose your sub-site settings.

    For the rest, just use the instructions from the link above.

    Good luck!

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

    Had same problem, found 3 possible solutions:

    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. (what solved it for me) Setting up multi-site for wordpress, changed the 'wp_blogs' table's column 'path' to an undefined location for my website. I changed it to "/" and the DB connection was re-established.

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

    I added $base = '/'; into the config, which solved the issue.

    define('MULTISITE', true);
    define('SUBDOMAIN_INSTALL', true);
    define('DOMAIN_CURRENT_SITE', 'mydomain.com');
    $base = '/';
    define('PATH_CURRENT_SITE', '/');
    define('SITE_ID_CURRENT_SITE', 1);
    define('BLOG_ID_CURRENT_SITE', 1);
    
    0 讨论(0)
  • 2020-12-24 14:31

    You need to add to your wp-config.php:

    define('MULTISITE', true);
    

    I had the same problem. I skipped this line because I already had define('WP_ALLOW_MULTISITE', true); in my wp-config and it looked to me the same.

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

    If you're running WHM/cPanel and you've already checked that you've added the MULTISITE/WP_ALLOW_MULTISITE constant, you're probably running into virtual host issues.

    If you're getting the database error, chances are, your name servers or A record is correct. Otherwise your domain wouldn't be pointing to your server with a database connection. But, you've probably forgotten, or missed, the domain name from the cPanel aliases.

    Just head to cPanel, search for 'Aliases' and type in the domain name you're missing under 'Create a New Alias'.

    You can also get to cPanel by logging into WHM, searching for 'List Accounts', searching for the account you want and clicking on the CP icon.

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