How to install multi wordpress blog under one database?

Sometimes we only have one mysql database, and we have several domain names. How to install wordpress for each domain under one database then?

Here is an example, say:,,,, and

First, you should choose one domain name as the main one, say,  and the others redirect to from your webhost cpanel.

Second, install wordpress under After installaction, login FTP, and open config.php. Two places need to be modifed:


/** The name of the database for WordPress */
define(‘DB_NAME’, ‘common databse name here’);

/** MySQL database username */
define(‘DB_USER’, ‘common database user name here’);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘common user name password here’);

/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);

Second, set up different mysql table prefix for each domain name.

// $table_prefix  = ‘wp_’;

$hostname = $_SERVER[‘SERVER_NAME’];
$hostname = str_replace(‘www.’, ”, $hostname);

// switch($_SERVER[‘HTTP_HOST’])
switch($hostname) {
case “”:
$table_prefix  = ‘opticalsaver_’;

case “”:
$table_prefix  = ‘eyeglassessaver_’;

case “”:
$table_prefix  = ‘eyewearsave_’;

case “”:
$table_prefix  = ‘glassessaver_’;

$table_prefix  = ‘eyewearsaver_’;
break;  }

Save and done!