Remote mysql connection - php

I work on a dictionary PHP project. Project owner has a dedicated server. They control server files via terminal. And they have a big database which include 370,000 words. In my program I want to connect to database. But the problem is that they don't want to upload my PHP project files to their server. Because they fear that the database maybe stolen by others. They say you can access our mysql server via some server info and they have send some information like this:
server ip : xx.xxx.xxx.xx
Port=3307;
UID=xxx;
pwd=xxxx
The thing that I know is if I want to connect a remote mysql server, The server owner must allow my IP address or upload project files to their server.
They say we don't have a ftp interface and can't allow remote IPs. You can successfully connect via mysql connector which written in php.
Is it possible to connect to the server only with this server information if the server owner not allow to my IP address for mysql connection?

No, it's not possible (with MySQL server default configuration) to connect to a remote MySQL server instance if your user id does not have permission to connect from the remote IP to MySQL server.
If you try to connect to local MySQL server these information would suffice but if you try to connect to a remote host with these information you might get an error like this:
"Connect failed: Access denied for user 'root'#'aa.bb.cc.dd' (using
password: YES)"
This indicates that your user id does not have permission to connect to the MySQL instance from this remote IP address.
But again you can try to connect to the remote MySQL server and get a connection back. It all depends on the remote MySQL server configuration.

The above information is enough to connect to MySQL server through php.
But if the server owner, has disallowed your IP for MySQL port, then you will not be able to connect.
But maybe that isn't the case, the IP disallowing can be application specific.
eg. they can disallow outside IPs to access there FTP and SSH but their MySQL port can be open for outside IP addresses hence can be accessed by you.

Related

How to Access a local MySql database from a remote server hosted in godaddy

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:
Configure MySQL to listen on your computer's external network interface (i.e. not on a UNIX socket nor on the loopback IP address).
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)
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

Find the Web Address for MySQL Database

I have got a cPanel hosting and I can create and log in to the phpmyadmin and change databases after I log in to the cPanel. What I need to do is log in to the same database even if my files are not on the same server, so I need to specify the exact database URL instead of "localhost". How do I get that URL?
The most secure way to access a remote database server is to setup SSH access on your database server and a SSH Tunnel on the web server that is hosting your files.
See: Connect to a MySQL server over SSH in PHP
This way you don't need to expose your database server to the internet, and instead can access it from the localhost of your web server.
If the database is exposed to the internet, you can assign a domain name to your database server and use that domain name, or subdomain, as the host and create a wildcard user like root#'%' but that is far less secure.

How to connect to remote DB server with IP address and mysqli_connect [duplicate]

I am trying to connect mysql database using php. But it is running fine on local machine but not when hosted online and error appeared as
mysqli_connect(): (HY000/2002): Connection timed out
<?php
$link = mysqli_connect('sql6.freesqldatabase.com','user_name','password','database_name');
if(mysqli_connect_error())
die("couldn't connect to database");
?>
Your MySQL server is probably not configured to accept requests from the host you're trying to access it from.
Check the configuration for the server.
Since you say the local machine can access it check where you permitted this and do the same for the ip of the online host.
In my case, AWS firewall was blocking my web server.
Adding the web servers IP address to the firewall exceptions fixed
this for me.
There might firewall in the host which is blocking the request to MySQL server. In my case adding the firewall rule helped me out.
Ubuntu
To allow one device to access the MySQL server,
sudo ufw allow from remote_IP_address to any port 3306
To allow any device to connect to MySQL server,
sudo ufw allow 3306
It worked!
If your website and MySQL database are hosted on separate servers, make sure that you've mentioned correct MySQL hostname (resolvable) in connection string.
In case you've specified the correct username, most probably your MySQL server isn't allowing remote MySQL connections from web server where you site resides.
Contact your web hosting provider for the exact MySQL hostname and to allow your web server IP address for remote MySQL connections.
I think you have to white list your hosting server's ip address to your DB server.
So your DB server will accept requests from your hosting server.
Specify the port (3306?) to the connection string as well.

How can I connect remote mysql db from my local?

When I try to connect to the remote mysql db from my local XAMPP php, it says,
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host
'testhost.testserver.com' (11004) in D:\xampp\htdocs\cvsprojects\test\initdb.php
on line 24
I am sure the mysql host, user name , password are correct to connect.
Your remote MySQL server must allow remote clients to connect. I Am quoting this from a web page
you need to have remote access privileges to the MySQL server. You must use your client IP address or a %-wildcard in the Host column of the mysql.user table next to your username. For more information on connecting to a remote MySQL server see the MySQL documentation (Security and GRANT topics).
Moreover, make sure your system can access the network your remote server is hosted on. After that its plain simple connection settings or strings as some call it.

Connecting remote server mysql database to localhost

How can I connect my localhost PHP files to my remote server MYSQL database?
For example: if we download WordPress, and it gives us an option to login, so that our login credentials are saved with WordPress but still our localhost files connects to that database.
How do I do that?
Thanks.
If you want your PHP code to connect to a remote MySQL database, you just have to specify that remote host when calling the function that connects to MySQL.
For example, when calling mysql_connect(), don't specify localhost as first parameter -- but your real remote host.
Same with mysqli::__construct() or PDO, of course.
A couple of notes :
Your remote host must accept connections to MySQL (think about the firewall)
Your remote MySQL database server must accept connections from non-localhost
Sending queries, and fetching results, to/from a far away server will be a lot slower than doing so on localhost !
mysql_connect(SQL_IP, SQL_NAME, SQL_PASS);
Well when you install Wordpress set the host to be the IP of your remote server. If this isn't what you're looking for, please reword your question. If you're not using word press, check ou the PHP documentation for mysql_connect. The first parameter is the host. Enter the IP or hostname of your remote server here. And then follow that with your username and password.
mysql_connect('remote-host', 'myuser', 'mypassword');
Note: Some hosts do not allow remote connections to MySQL. Check your remote server doesn't have 3306 firewalled or only instructed MySQL to bind it to 127.0.0.1.

Categories