Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Can a domain communicate with database on another account?

Discussion in 'Database Discussion' started by biggsy, Jan 20, 2011.

  1. biggsy

    biggsy Member

    Jan 20, 2011
    Likes Received:
    Trophy Points:
    Hi there, I have a few domains on my cpanel server which use a db and there is also a 'master' site which is trying to connect to the databases on the other sites. On an old plesk server we achieved this by using the mysql root password.

    I wondered if this is possible with cpanel where domain 1 can talk to domain 2's database.

    They are the same owner (root).

    Does anyone have any ideas?


  2. cPanelDavidN

    cPanelDavidN Integration Developer

    Dec 17, 2009
    Likes Received:
    Trophy Points:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Sharing databases between cPanel accounts.

    Hi Andy,

    So, each domain is on its own cPanel account, right? Currently there's not an out of the box solution for this. Depending on how you plan to access the databases, you may have an easy option that's not provided in the the cPanel interface.

    If you just need web applications on each domain to access the same database, you can just simply provide the database credentials to the application. Since it will operate complete outside the scope of cPanel, there's no need to establish if the cPanel account who's domain is servering the application has "permission" or a sense of "ownership" on the database.

    If, on the other hand, you need cPanel to list the "shared" database, or to use phpMyAdmin on any given account with "shared" access, it's a little more involved. Normally, I don't recommend sharing databases between accounts, but I understand that in some situations there's a valid reason. Below I've itemize how this is done in brief and then in detail; you'll need root access to the server (or at least a reseller with "all root" privileges if you use WHM). If you don't have root, and you've got multiple cPanel accounts, and you're sharing databases, I'd consider getting a VPS. You can usually get one at a reasonable price and you will have root, which will make various customizing easier (and this how-to possible).

    Short steps:
    1) add "shared" db name to each cPanel account's DB resource file (/var/cpanel/databases/$cpuser.yaml)
    2) remove each cPanel account's DB Resource cache file (/var/cpanel/databases/$cpuser.cache)
    3) invoke the Mysql::updateprivs call to add proper MySQL privileges

    Each cPanel account has a DB resource file. If your cPanel account name is 'john', then it will be /var/cpanel/databases/john.yaml. There will also be a cached version /var/cpanel/database/john.cache. These files are only writable by root. This pair of files can be considered the authoritative list of databases for the cPanel account (at least as far as cPanel code is concerned).

    In order the cPanel UI and phpMyAdmin to "see" that you have access to this database, you'll need to update those files as well as have the proper privileges set within MySQL. So the easiest way to do this is:

    1) log into WHM as root (or reseller with 'all root' privileges) and navigate to the SQL section
    2) select "Database Map Tool"
    3) select the cPanel account that you want to "share" the database with
    4) in the "Database Names" field put in the full, literal database name that you are sharing (the database must already exist, ie: 'john_wordpress1')
    5) click "Submit Query" and you should receive a message noting that "The user's dbmap has been updated"

    At this point you've update the DB resource files. Now we must add the MySQL permissions for the cPanel account the "shared" database. You could log into MySQL an manually add the permissions, but the following is much easier:

    6) log into cPanel as the user whose "dbmap" you just "updated"
    7) select the "MySQL Databases" icon, this should take you to the cPanel UI for managing your cPanel user databases (and virtual db users).
    8) you're done. Just by loading this page, cPanel invokes the Mysql::updateprivs API call. The purpose of this API call is to ensure that databases itemized in the user's "map" file have the respective MySQL privileges within MySQL.

    Now you just do it all the cPanel accounts you want to add to the "shared" database. This process with only work on cPanel 11.28 or higher. This is due to DB Mapping feature set that was introduced in that release. It's possible that this procedure will change as the DB Mapping feature set matures, but there is no such plan at this time.

    Hope this helps.


    PS. for anyone interested, this information and more concerning DB Mapping is available in a white paper here,
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice