如何从godaddy中托管的远程服务器访问本地MySql数据库

如何从godaddy中托管的远程服务器访问本地MySql数据库

问题描述:

I am trying to access a database which is in root@localhost from a website hosted by godaddy.

i created a php file in the project folder and trying to access the local mysql database

here is the code

//actionpage.php

<?php

$db=mysqli_connect("127.0.0.1","cancan","canpass","test");


if (!$db) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";

?>

it gives me the error on the browser

Connection failed: Access denied for user 'cancan'@'localhost' (using password: YES)

The website i created is just static html without a back end..

I am pretty new to back end developing , Please help me

So long as Godaddy doesn't block outgoing MySQL connections and your ISP doesn't block incoming MySQL connections, this is technically possible.

You would need to:

  1. Configure MySQL to listen on your computer's external network interface (i.e. not on a UNIX socket nor on the loopback IP address).
  2. Ensure that the MySQL service is available on the Internet (which will probably mean configuring your Internet router to perform port forwarding for the MySQL port from the Internet to your development machine)
  3. Change the connection string in your PHP so it connects to the hostname or IP address of your computer on the Internet (probably your router's external IP address).

You'd probably want to ensure you have a static IP address on the Internet so that you don't need to update the PHP every time your IP changes.


This, however, will be slow (because your MySQL traffic has to go back and forth across the Internet) and risky from a security perspective.

So don't do it. Get a MySQL service from Godaddy.

GoDaddy can't access database which is hosted on your computer. For that to be possible your computer must have a Public IP address, It's only that way you can connect website hosted on GoDaddy to your local database and for that you must reference you local computer by their Public IP address and not as localhost within your phone script.

When you use localhost in script host on GoDaddy It will not reference your computer but the server on which that script is hosted