Share users database on different WordPress installs

Remi | November 1, 2012 | in Tutorials

It’s pretty useful to be able to share the same users database over two WordPress installations. This method is used by many important websites to keep sessions opened between different websites, domains or sub-domains. Here is a simple way to share users database:

Share users database to create a great user experience

Let’s say you have an existing WordPress installation, and you want to share the existing users database with a second website.

First of all make sure you are using the same WordPress version on the two websites and make sure your two websites are using the same database. To be able to have the two websites using the same database, you have to use different table prefix for each install.

To change the default WordPress table prefix, you have two choice. You can do it during the installation or editing the wp-config.php file where you must change $table_prefix value.

Once the second website has been installed, add these two lines in wp-config.php file, just before this line:

/* That's all, stop editing! Happy blogging. */

Add these two lines:

define('CUSTOM_USER_TABLE', 'wp_users');
define('CUSTOM_USERMETA_TABLE', 'wp_usermeta');

Make sure you replace “wp_” by the first website table prefix.

With this code you’re asking the second website to use the first website users table. Isn’t it great?

Now we are facing a small problem. Cookies… Yes, each website has its own cookies parameters, so your two websites have to use the same cookies parameters. So, still in wp-config.php of the second website, change the COOKIE_DOMAIN with the url of the first website:

define('COOKIE_DOMAIN', ''); //replace with the 1st website url
define('COOKIEPATH', '/');

And now your’re done, now logged users will have their sessions opened accross your two websites.

The author

About the author Remi: Hey! My name is Rémi Corson, i'm a WordPress Expert Developer, i create high level themes and plugins, and i provide free stuff every week on this website!


  1. jeremy buller

    I’ve wondered recently whether this was possible! Thanks for sharing.

    I have one WP installation at a particular domain, and a second at one of its subdomains (like – and When I tried to implement this in’s wp-config.php, I started getting the message ‘You do not have sufficient permissions to access this page.’ for all users at

    Undoing these definitions doesn’t seem to be helping. Have you seen this before, by any chance?

    1. rickky

      Hi Rémi,

      After 4-5 hours search I found your site. I hope your code will help me. Right now I am trying it in my localhost but its not working for me.. I am using woocommerce and one event plugin in my wordpress websites. I have 2 website on server. But right now I am testing your code in my localhost. I installed 2 wordpress different folders name under localhost. Both have same woocommerce and event plugin. Now I want if I update in my first website then my second website will be show that update on page. I want to do this with my event plugin If I update my event on my first website then it will update on the second website automatically.

      I tried your code but get nothing. Can you please give me little time to solve my issue.

      I use this code under my config file
      define(‘CUSTOM_USER_TABLE’, ‘wp_users’);
      define(‘CUSTOM_USER_META_TABLE’, ‘wp_usermeta’);

      Now I can’t login under my second website admin. I update content in my first website but nothing update on same page of my second website. Please let me know where I am doing mistake. Thanks


  2. Aaron

    Is it possible to share users between a site with a standard wordpress install and a site with a multisite install? Would this cause any issues?

  3. Rıfat

    i think something wrong with this.

    define(‘CUSTOM_USERMETA_TABLE’, ‘wp_usermeta’);

    must be;

    define(‘CUSTOM_USER_META_TABLE’, ‘wp_usermeta’);

    it worked for me like this.

    But i have another problem. When i try to login to 2nd wordpress. Nothing is happening. Its just refreshing the page and thats all.

    In my situation i have some users on my 1st WP installation. Then i connect it to the second one.

    Any suggestion?

    1. Rıfat

      Fixed it.

      Its because of the cookie thing. That didnt worked for me. When i delete the lines:

      define(‘COOKIE_DOMAIN’, ‘’); //replace with the 1st website url

      define(‘COOKIEPATH’, ‘/’);

      It just worked.

      Anyway, thanks.

        1. manoj

          suppose i have two WordPress install on different databases, which are in the same server. how can i archive user sharing for both sites….
          if some registers to site A then he would be also registered to site B automatically.

  4. VK Jain

    I don’t see this anywhere in my wp-config.php file
    define(‘COOKIE_DOMAIN’, ‘’); //replace with the 1st website url
    define(‘COOKIEPATH’, ‘/’);

    Where should I find this to change the COOKIE_DOMAIN?

  5. Kriss

    Hi Remi, I really could do with some help.

    I current have two wordpress servers, with separate IP’s (so the server are not linked so far).

    I would love to have both wordpress installs share the same user information. How can I do this, as the server aren’t even connected?

    Is it similar to your instructions above, but somewhere I need to add an IP or URL of the server?

    Any help would be extremely appreciated.

    1. Remi Post author

      The two websites HAVE TO use the same users table. If your servers allow distant connections that shouldn’t be a problem, but unfortunately i’m not a server expert!

  6. Morten


    Tried adding and changing, but when I go to second site it just opens a blank page.

    So where am I to add the cooking thing, and how should the site url be shown?

    Hope you can help.


  7. Rob

    Hi Remi,

    This is just the information I need – but I can’t make it work – unless I’m misunderstanding.

    What I’d like to do is be able to log into my primary domain – and from there click on a link that will bring me to the subdomain – – and be automatically logged into the subdomain.

    In other words, I want my users to be able to just log in once – on either domain – and be able to go back and forth between the domain and the sub-domain without having to login more than once.

    I do have things configured right now so that the users of my domain can log into my subdomain – but they have to log into each one individually. Is this the best I can get?

    I’ve tried, I think, every combination possible – even copied the keys/salt/auth/nonce from my domain’s config and tried it in the subdomain.

    Right now I just the “wp_users” and the “wp_usermeta” lines and my users can log into each domain individually. The “cookies” lines didn’t seem to have any impact.

    Any ideas?

    Thank you very much!

    1. Remi Post author

      Hey Rob, i guess it’s a matter of cookies/sessions that needs to be fixed, nothing more. If you create two cookies/sessions (one for each site) when a user logs in from one domain, you should be fine.

  8. vajrasar

    Can you please explain this – “your two websites are using the same database”?

    I din’t get the gist of “using the same database”? Can you give some example?

    We have and (as subdomain). on we post news and on we do reviews. Both are separate wordpress installs with their own databases. How can I use your awesome solution with this setup?

  9. cardened

    Hi Remi.

    Thanks for sharing. Something is not clear for me though.

    I have two wp installs on the same domain.
    WP Install 1:
    WP Install 2:

    define(‘COOKIE_DOMAIN’, ‘’);

    should be like this:
    define(‘COOKIE_DOMAIN’, ‘’);

    Is that correct?

    And SECOND:
    You have this:

    >>define(‘CUSTOM_USER_TABLE’, ‘wp_users’);
    define(‘CUSTOM_USERMETA_TABLE’, ‘wp_usermeta’);

    Make sure you replace “wp_” by the first website table prefix. < WP Database Name: _wrdp1
    WP Install 2: –> WP Database Name: _wrdp2

    Where or how should I change this?

    And THIRD:
    How can I make sure I’ve done the changes correctly? When I get on the second site and look at USERS, should I see all the users as in the first wp install?

    Thank you very much for your kind support!


  10. cardened

    Hi Remi!

    Thanks for this post. I managed to do everything that you mentioned, BUT I am having the following problem.

    It is not passing the “MEMBERSHIP LEVEL” that I setup on the main blog. How can I do this change now that I’ve already installed the site and wp-config.php is already configured?


  11. Pingback: Multisite WordPress dengan Satu User | Herupurwito's Blog

  12. pkapila

    Hello Remi,

    I had followed you steps defined above, and am facing a problem with only how to set cookie for the second site to validate.

    this code is not working for me can you please help me out…

    define(‘COOKIE_DOMAIN’, ‘’); //replace with the 1st website url
    define(‘COOKIEPATH’, ‘/’);

    for example my first site is at and the second site is at

    the second site uses the user table of the first site but is not logges in the user if the is already logged in the first site.

    Thanks Prashant

  13. shareef

    Hi Remi,
    I tried all these steps you mentioned here except cookies things and i succeed for two of my sub-domains running WP. Now i can login using same username and password for admin and front of both sub-domains. But i am facing a problem that is i have to login separately for the front of both sites.
    What is need is to login once only on any site and remained login for second site when go to that..There is some problem in cookies but no idea where it is?
    Any help praised??

  14. iMJohanes

    Hi Remi,

    Could you teach me how to do it if my main site database isn’t same with the subdomain database. But they’re both in the same server.


  15. AnDr3yy

    Hi there,

    I need some help. I try your method, I put the 4 lines of code in wp-config.php, but I can’t login with any user on my second wordpress site.

    Ai have this message every time:

    You do not have sufficient permissions to access this page.

  16. estiner

    Okay, I think I’m so close on this one, but I can’t quite get over the hump. I have installed both WordPress sites using the same database and changed the $table_prefix value in site B to a different value. Everything is working grand. But…when I then add the two define function lines given above (my first site’s $table_prefix value is wp_) into site B’s wp-config file and I refresh my site, it no longer lets me log into my WordPress dashboard for site B. The site appears fine, but its like my user credentials no longer work. Any thoughts on this?

  17. marieneige

    Hi I wonder how that works really because to share a database I think you have to run a multisite but if running a multisite then there is no place to add a special prefix in wp-config.php for each of the multisite. I run a multisite, would this work ? if not, how ? thank you

      1. marieneige

        oh but when I switch from a subfolder site to another the cookies are not shared, so the cart and wishlist content are not synchronized. If I isert this code : define('COOKIEPATH', '/'); I have trouble login-in.
        I would like also to share users on two sister-sites wich don’t share the same database, one is old and one is going to be launched soon but I already made a lot of databases in it and.. they have the same table prefix. How I can share the users? What would happen if in my new site on define('DB_USER', 'database_name'); I would insert the database name of my old site? thank you so much!

  18. Sanjeevan


    I am in the process of setting up a online store (woocommerce), with a lot of other additional features such as blog, business directory (business directory plugin), classified (AWPC plugin), event listings (Events Manager Plugin) & Forum (bbpress plugin)

    I realize that by having all this my site is a bit slow. I was thinking of splitting the site into multiples installs, such as,, etc.. and keeping the woocommerce shop on the main url

    What is your advice ?

    I should be able to use one user registration across all installations. and once logged in the user should be able to visit any of the sub domains, and it should show as logged in..

    Are there better ways to do this ?

    Or should i stick to one install and work on improving they site speed using other methods such as caching etc..

    Appreciate your reply.


  19. Pingback: The Kristna – Share users database on different WordPress installs

  20. Pingback: Sharing woocommerce product data - Wordpress Helpdesk

  21. Pingback: Sharing woocommerce product data - Technology

  22. Gaurav

    Hi All

    I have 2 WordPress sites in 2 different sub-domains like and . Both sites have wp-require plugin activated and only logged-in users can see the site. I want to make a system where if a user logged into one site, he should be auto-login into the other one.

    What i try :

    After some searching I know I need to use one database for both sites. So I have done these steps:

    I have download the whole database of site and change all prefix wp_ to wpmo_, replaced it in whole database and upload it into first site’s database. I added these 2 lines in wp-config.php of the second site, to define that second site should use first site’s user table not its own.

    define(‘CUSTOM_USERMETA_TABLE’, ‘wp_usermeta’);
    define(‘CUSTOM_USER_TABLE’, ‘wp_users’);
    Now, the second site is using the first site’s users and I am able to login to the second site by the user details of first site.

    The next problem is cookies, so I added these lines in wp-config of both sites.

    define(‘COOKIE_DOMAIN’, ‘’);
    define(‘COOKIEPATH’, ‘/’);
    define(‘COOKIEHASH’, ‘aee53c017c29dc0d3ae37253fc8cbfd8’);
    Now I logged in into and when I go to , it asks me to login. That means cookies are not passing from the first site to the second one. However, i tried to be print $_COOKIE and it gives me same encrypt values, but user still not auto login on second site. also when i came back to first site , it automatic logout. i feel like both sites are related somehow on cookies and i am close but still not reached to my goal of auto login into second site.

    Any help?

  23. Intervik

    Hi Remi
    I try to get a question-mark about this topic to be straighten out, all over Google and forums.

    In many certainstances myself and other people looking for a way to make an excisting wordpress installation using a shared user table as a slave to another “master” install, on diffrent domains. All are saying just like your post here on your site.

    But, after changing the slave database connection, the excisting slave installation wanna re-install, and after that, the install is a new blank wordpress from scratch – with sharing usertables.

    This means (?): You CAN NOT connect an old install – it will be NEW anyway. And then, in many cases, it is better to make a clean salve install from the beginning – to make rid of the fuzz to re-name the table prefix on the slave installs and more…

    Im I correct or am I missing something obvious here?

    Thanks for a nice knowledge-bank you got here…

    / Jonas, Intervik

  24. askindia1996

    Hello Remi,

    I am facing issues with login/logout session sharing. However, users are able to login manually after i pasted define(‘CUSTOM_USER_TABLE’, ‘wp_users’); and define(‘CUSTOM_USERMETA_TABLE’, ‘wp_usermeta’); in my second website’s Wp-Config file, but the session sharing is not working. Could anyone please help me ?

  25. digosw

    I’ve tried to do that “define(‘CUSTOM_USER_TABLE’, ‘wp_users’); and define(‘CUSTOM_USERMETA_TABLE’, ‘wp_usermeta’)” on the second web site… But it didn’t work.

    I have to do something more?

    (sorry for the bad english… i’m getting rusty… :P)

Leave a reply