0

I am running mysql on a linux server. I have the linux server IP and mysql runs on localhost on that linux server. Now how do I access mysql running on localhost server remotely?

I can do this by ssh into linux server then running mysql, but how would I do it with in a php script? For example...

<?php
$servername = "localhost";
$username = "username";
$password = "password";

try {
   $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, 
           $password);

   // set the PDO error mode to exception
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  echo "Connected successfully"; 
}
catch(PDOException $e)
{
  echo "Connection failed: " . $e->getMessage();
}
?>

(this script only connects to mysql directly which is not possible remotely)

In my script I would need to access linux server then mysql server unless there is a way to access mysql directly (remotely). How is this achievable?

Zahidul Islam
  • 99
  • 1
  • 9

2 Answers2

0

You need change bind address in my.cnf and restart your mysql service.

Official documentation:

https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_bind_address

If the address is 0.0.0.0, the server accepts TCP/IP connections on all server host IPv4 interfaces.

By default all connections restricted localhost.

erroia
  • 378
  • 3
  • 10
0

In order to access your mysql instance from your server; you need to install workbench (or some other mySql explorer) on your development machine.

Create a connection to mysql instance using server ip address as host name and provide username and password to open connection. If every thing goes well you will see your databases in explorer.

Zeeshan
  • 619
  • 4
  • 16