0

How to connect remote MySQL database in PHP

Spread the love

Suppose you are working on a project and your code or application is hosted on a server and your mysql database is hosted on another server but you need to get your mysql database from code server remotely then this post is for you

In Some Projects we need more then one database to work on.So we have to get access of mysql server remotelly from different servers.By Default for security purpose remote access to MySQL database server is disabled in shared hosting.So we have to enable it by adding other IPs and servers

Remote Access will allow MySQL access from another server.This will help us when we want to connect multiple databases (hosted on different servers) to a single project.This Post will help you on “How to connect remote MySQL database in PHP.

Suppose your database hosted on shared hosting (SH-1) and your application on another host (SH-2). And you are looking solution to connect your SH-2 application server with SH-2 Mysql server then follow below steps.

access mysql database remotely, connect to remote database, connect to remote mysql database using phpmyadmin, how to connect mysql database from another server in php, mysql connect to database on different server, mysql connect to remote database command line, php connect to remote mysql server

Step-1: Login to your shared hosting cpanel.

Step-2: Under the Databases section, click on Remote MySQL®.

remote-mysql-connection-php


Step-3: Enter the IP address of application host server (SH-2) from where you need to access mysql database to authenticate connection for (SH-2).
remote-mysql-connection-php-1

Step-4: For making connection with database hosted in shared hosting server (SH-1) from another application server (SH-2). you just only add the host name of mysql server and database name with their username and password in php connection code. Now your mysql server (SH-1) will easily authenticate connection request from application server (SH-2).

If connection will successful it’ll return message like “DB Connected successfully” and you’ll able to access mysql database and execute mysql queries from application server (SH-2) , If not then it’ll return connection error.

Leave a Reply

Your email address will not be published. Required fields are marked *