How to connect to a MySQL database which is on another server?

13 replies
Hello Warriors,

I am looking for someone who knows about MySQL databases and cpanel servers..

I am trying to connect to a database from one site to the other..

Site A is my main site and has the database on it, now site B is my other site and I am trying to connect to the database on site A from site B.

I know it can be done just can't figure out how, I set the IP address and domain name and even % in the "Remote MySQL" on my Cpanel..

Any help will be greatly appreciated..

Dennis
#connect #database #mysql #server
  • Profile picture of the author SuzanneH
    Are they on the same server though? I have two separate websites on the same server and I can easily access my databases from either site...

    Suzanne
    {{ DiscussionBoard.errors[150784].message }}
    • Profile picture of the author Dennis Cheesman
      Yes, they are on the same VPS..

      If you don't mind me asking what do you use to connect?

      Dennis
      {{ DiscussionBoard.errors[150789].message }}
      • Profile picture of the author SuzanneH
        I use the exact same code to access the database with mysql_connect():

        PHP: mysql_connect - Manual

        Use 'localhost' as the server name.

        Example:

        I'll pm you the example; the board is cutting out some of the code, even though I'm putting it in the code brackets...

        Suzanne
        {{ DiscussionBoard.errors[150806].message }}
  • Profile picture of the author Dmitry
    Are you trying to make a script connect to the DB on the other server?

    EDIT: If they are on the same server you don't have to setup IP or domain, just use localhost. But it's been awhile since I last used MySQL so I might be wrong.
    {{ DiscussionBoard.errors[150791].message }}
    • Profile picture of the author Dennis Cheesman
      Yes, see I have a membership site on the main site and I am trying to connect to that from the other site to populate it as well, and because new things are added they will be added to both sites..

      Dennis
      {{ DiscussionBoard.errors[150797].message }}
  • Profile picture of the author Jeff Usher
    [DELETED]
    {{ DiscussionBoard.errors[150801].message }}
    • Profile picture of the author Dennis Cheesman
      Hello Jeff,

      They are on the same VPS and I did all you mentioned and have the connect script like so on site B:

      <?PHP

      myserver=="Site A IP Address";
      myuser="site-username_db-username";
      mypassowrd="password";
      mydatabase="site-username_dbname";

      //For Site B Server
      mynewserver="Site B Domain name";
      mynewuser="site-username_db-username";
      mynewpassowrd="password";
      mynewdatabase="site-username_dbname";

      myconn= mysql_connect(,,) or die (mysql_error());
      mydb= mysql_select_db(,) or die (mysql_error());

      mynewconnect= mysql_connect(,,) or die (mysql_error());
      mynewdb= mysql_select_db(,) or die (mysql_error());

      ?>

      And this is the error I am getting:

      Warning: mysql_query() [function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/username/public_html/members/index.php on line 14

      Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/username/public_html/members/index.php on line 14
      Access denied for user 'nobody'@'localhost' (using password: NO)
      Dennis
      {{ DiscussionBoard.errors[150808].message }}
  • Profile picture of the author Jeff Usher
    Dennis,

    If they are on the same server then you should just be able to input the same database connection settings in both sites.

    If you need a hand just PM me and I'll take a look for you.

    Regards

    Jeff
    {{ DiscussionBoard.errors[150802].message }}
  • Profile picture of the author Jeff Usher
    Dennis,

    That error indicates that the database settings are not input correctly otherwise:-

    nobody'@'localhost

    would be replaced by the actual username@localhost

    I would check the config files again to check the username and password have been saved correctly.

    Jeff
    {{ DiscussionBoard.errors[150813].message }}
    • Profile picture of the author Dennis Cheesman
      Hello Jeff,

      I know it sounds weird, but the database information is correct

      It is crazy...

      Dennis
      {{ DiscussionBoard.errors[150840].message }}
      • Profile picture of the author KarlWarren
        Dennis,

        did you copy the config info in your quote above directly from the file?

        If so, (it may not be the case):

        mynewpassowrd

        This typo could be something to do with it.
        Signature
        eCoverNinja - Sales Page Graphics & Layout Specialist
        {{ DiscussionBoard.errors[150850].message }}
        • Profile picture of the author Dennis Cheesman
          No, thats not it because it works on the main server..

          But I changed it anyway

          Dennis
          {{ DiscussionBoard.errors[150856].message }}
          • Profile picture of the author Dennis Cheesman
            I really appreciate the help

            I got it figured out

            Dennis
            {{ DiscussionBoard.errors[151025].message }}
  • Profile picture of the author Jeff Usher
    Dennis,

    If you PM me I'll take a look for you and see if I can spot anything if you like.
    Sometimes a 2nd pair of eyes can spot things the first pair has missed

    Regards

    Jeff
    {{ DiscussionBoard.errors[150848].message }}

Trending Topics