Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress Multisite "Error establishing a database connection" in localhost

Tags:

wordpress

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

Error establishing a database connection

I'm using WordPress 3.7.1 on Windows 7 with a WAMP server.

wp-config.php

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

.htaccess

RewriteEngine On  RewriteBase /wordpress_test4/  RewriteRule ^index\.php$ - [L]  # add a trailing slash to /wp-admin  RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]  RewriteCond %{REQUEST_FILENAME} -f [OR]  RewriteCond %{REQUEST_FILENAME} -d  RewriteRule ^ - [L]  RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]  RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]  RewriteRule . index.php [L] 
like image 951
user1987095 Avatar asked Nov 01 '13 10:11

user1987095


People also ask

How do I connect my WordPress database to localhost?

Navigate to http://localhost/phpmyadmin. Where it says create new database, choose a name for your database. Next, open up wp-config. php in the root of your wordpress folder, and update the four values shown below to reflect your new database.

What does it mean when it says error establishing a database connection?

This error means that your website files (on the webserver) are not able to connect to your database (on the database server). This article lists some common reasons this error could display on your site, including: Incorrect database credentials in your config file. The hostname isn't working.


2 Answers

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.

like image 58
Dima L. Avatar answered Oct 08 '22 11:10

Dima L.


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. But what solved it for me* is etting 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.

like image 39
Sabin Chirila Avatar answered Oct 08 '22 11:10

Sabin Chirila