Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm looking for a way to separate my users and usermeta table to be in a different database than my main WP install. The end goal is sharing these table over a number of WP installs.

From what I read, HyperDB should allow for this, however their documentation is a little sparse when it comes to creating and linking datasets --- which is where I believe I should be looking.

I've tried something along the lines of this without success:

$wpdb->add_database(array(
    'host'     => DB_HOST,
    'user'     => DB_USER,
    'password' => DB_PASSWORD,
    'name'     => 'my_user_db_name',
    'write'    => 0,
    'read'     => 1,
    'dataset'  => 'user',
    'timeout'  => 0.2,
));

$wpdb->add_table( $user, $wpdb->base_prefix . 'users' );
$wpdb->add_table( $user, $wpdb->base_prefix . 'usermeta' );

But this wasn't successful. Any help would be appreciated. Thanks in advance. ~Cam

share|improve this question
add comment

1 Answer

Problem solved. Here is what I did:

$wpdb->add_database(array( //Connect to Users Database
    'host'     => DB_HOST, // I am using the same host for my two DBs
    'user'     => DB_USER, // I am using the same username for my two DBs
    'password' => DB_PASSWORD, // I am using the same p/w for my two DBs
    'name'     => 'my_user_db_name', 
    'write'    => 0, // Change to 1 if you want your slave site's the power to update user data.
    'read'     => 1,
    'dataset'  => 'user',
    'timeout'  => 0.2,
));

$wpdb->add_database(array( // Main Database
    'host'     => DB_HOST,
    'user'     => DB_USER,
    'password' => DB_PASSWORD,
    'name'     => DB_NAME,
));

$wpdb->add_callback('user_callback');
function user_callback($query, $wpdb) {
    if ( $wpdb->base_prefix . 'users' == $wpdb->table || $wpdb->base_prefix . 'user_meta' == $wpdb->table) {
        return 'user'; 
    }
}

Be warned that if plugins have tweaked with your admin permissions (I have one that does), the sites you connect will have to have been tweaked as well.

I have seen several people with this question: How to share users between Wordpress installations while not using the same DB? With HyperDB, I was able to solve this!

share|improve this answer
    
On further testing, this doesn't seem to work, however, I haven't figured out why or what is missing. –  Crazycoolcam Mar 1 '13 at 22:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.