Connect to Azure MySQL Database - php

I'm trying out Azure for the first time. I followed this guide to create a web application with a MySQL database.
So the DB node was create and I can see it in my resources and I can view the credentials in the properties. However, I can't connect to it from my desktop.
It looks like a firewall issue as I'm unable to telnet to it:
telnet us-cdbr-azure-west-c.cloudapp.net 3306
Trying 104.209.43.4...
telnet: connect to address 104.209.43.4: Operation timed out
telnet: Unable to connect to remote host
Can anyone tell me what I'm doing wrong?
Thanks in advance.

Usually, this issue is raised due to IP or Port is blocked by firewall.
As the comments show that others can connect to your MySQL server, so I think we can exclude that server side firewall blocked your IP and Port.
If you are in a protect network environment, check whether the gateway of network has a white list and your MySQL server endpoint is in the list, or whether the gateway has block the 3306 port. You can change a network environment if possible to check this.
Another attempt is that you can change a PC to have a test to connect to your MySQL server. If it could work, you can compare with the successful PC firewall configuration.

Related

Cant connect to mysql server (hosted by strato) get error 10060

Hi I am trying to connect to my MySQL DB which is hosted by strato. On their site I can create a DB and I did. Now I am trying to connect to the database via NaviCat but I keep getting error 10060.
A screenshot of the strato website: screenshot strato webportal
A screenshot of my trying to connect to the database in NaviCat: screenshot NaviCat
And last but not least a screenshot of their website with an tutorial on how to connect to the DB: link to page
Maybe you're wondering why I don't contect the host, it takes ages for them to reply...
What am I doing wrong why cant I connect how can I fix it?
EDIT/UPDATE
I now setup a SSH tunnel but when I am trying to connect it still gives me this errorlost connection to mysql server at 'reading initial communication packet' system error 0
I am able to connect via PuTTy like shown in this link. And a found the port, hostname etc as you can see
But once I fill that into NaviCat, like this
and this
but still no luck :S now gettings this error:
If anyone can help me i would rlly appreciate it!
My guess is that Strato is blocking outside access to your database. Which is 100% good. Allowing internet access to a database is generally a bad idea.
You can connect to the database by SSH'ing to the server and then using mysql CLI. Instructions are provided in the link you shared in the SSH-access to the MySQL database section.
Using SSH you can also port tunnel to allow your remote connection with your client. This is a slightly more advanced technique where you link up a port on your local computer (localhost) to a port on the remote machine to which you are ssh'ing.
In PuTTy put in the server name like their instructions suggest:
Then go to SSH>>Tunnel in the left-hand menu. Fill out your Source Port (the port your local computer will be listening on) and your Destination (The server:port on the REMOTE computer that you are forwarding traffic to through the tunnel):
I'm using local port 66306, you may use whatever port you want as long as it isn't be used on your computer. Click "Add" and then Open the connection and put in your username/password when prompted. Refer to that Strato help doc if you get stuck.
NOW... in your mysql client (Navicat) you are going to connect your database. Because you have a tunnel open forwarding traffic from YOUR computer's 63306 port (or whatever port you chose) to the remote computers 3306 port you will specify in Navicat:
Connection Name: Whatever
Hostname/IpAddress: localhost
Port: 63306
Username: strato db username
Password: strato db password
Now it should connect. Strato sees your traffic as if it's coming from their server because of the tunnel and it will allow you through.

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.

Unable to connect to MySQL Database on RDS from application hosted outside AWS

I have authorized connection to RDS by adding the CIDRs as mentioned in the AWS documentation.
So I am able to connect and manage my RDS instance from local system(I added my local ip in CIDR)
My application instance is resting on a server that is outside AWS and is unable to connect to the database even after adding my application server IP to CIDR allowing only one IP /32.
when i try to open my application, i get this error
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on '<rds endpoint>' (4)
Did others face the same problem?
How did you go about solving it?
Regards
Ravi
Is your application behind a firewall or front-facing? Does it have a public IP or is it using an internal IP on your network? It may be an issue that you may need to allow the front-facing IP access on your security group to access the RDS instance if your application server is behind the firewall.
The issue is fixed now.
Realized that my mysql port 3306 was blocked on the server and was not allowing any communication responses.
Thanks for the help though.
edit:
So, here's how the issue was solved.
RDS allows incoming connections from two sources.
1. Trusted IP
2. ec2- security group
When allowing connections from any outside IP, we have to add that IP or IP range to the security group in RDS instance. It is available in RDS console.
Click here to know more details
The outside server also should allow communications via mysql port(3306), so make sure that you enable 3306 on your application server.
Change your host to the RDS endpoint and test. It should work.

Cannot connect to mysql database on remote host

I am not sure if the terms I am using are correct so ask for clarification if you need :).
Anyways, I am hosting through HostEasySolutions (Server A). It comes with a MySql database, using PHPMyAdmin as the frontend. On Server A, I added some PHP files to access the database, and it works fine.
If I copy the php files to my other server, through DreamHost (Server B), I cannot connect to the database. I get the error: Can't connect to MySQL server on 'combinedsystems.ca' (110)
In the cPanel on Server A, I added the IP for Server B into the Remote Database Access Hosts, I also just added the wildcard '%', just to see if I could get it working...but still it can't find the server.
I am not sure what is going on, as far as I can see there is no firewall.
The only thing that stands out to me, is that if I go to PHPmyAdmin for Server A, it says Server: Localhost via UNIX socket, where as for Server B's PHPMyAdmin, it says: Server: mysql.pdem.info via TCP/IP
Most (all?) hosting companies have port 3306 closed on the firewall.
What you need to do:
adding remote database access in the database
edit my.cnf to listen on all interfaces. Default mysql listens only to localhost
most of the time you are out of luck! Even if there is no firewall (would be very unsecure) you have no access to my.cnf

mysql_connect() works fine on localhost but not when accessing seperate ip

I'm working with my University's Systems Administrators to get a LAMP stack setup for me. I'll need to access this server from several websites that I'm working on and I'm having some issues.
So to keep thing's clear:
LAMP Server URL = https://mysqlserver.edu
School URL = https://schoolsite.edu
When I run mysql_connect() on the LAMP Server it connects fine:
mysql_connect('localhost', 'user', 'password'); Works great!
However, when I run mysql_connect() on the School URL I can't connect:
mysql_connect('mysqlserver.edu', 'user', 'password');
Warning: mysql_connect(): Unknown MySQL server host 'mysqlserver.edu' (1) in /home/content/x/x/x/xxx/html/testconnect.php on line 3
Unknown MySQL server host 'mysqlserver.edu' (1)
What do I need to ask the System Administrator to do in order to give my PHP scripts on external sites access to the MySQL server?
Does the SSL complicate issues?
I appreciate any insight you might be able to provide.
Unknown MySQL server host probably means that your machine cannot resolve to hostname mysqlserver.edu, have you tried connecting via IP address?
After you make sure you are resolving the name, you have to overcome three further barriers:
firewalls as others have shown,
MySQL server configuration which has to allow remote connections and
a user able to connect remotely has to be setup.
MySQL user depends on the computer it is access from. 'root#localhost' is not the same root as 'root#192.168.0.156'. So you have to add the user from the computer you are going to access from. So let say the computer where php script is served is '192.168.156' you need to add a user 'user#192.168.0.156' to the MySQL server and don't forget to set the privilege for that user to access to the database needed.
Hope this helps
It's rare to make a MySQL connection over a public WAN. It's common to take a LAN hop or two but you usually can't cross a firewall for security reasons. That is, incoming TCP connections to port 3306 are being blocked by the firewall or gateway onto the local LAN where mysqlserver.edu is.
The canonical test for this is:
$ telnet mysqlserver.edu 3306
I can predict that this will not work. ("Work" means that it reports "Connected to..." and outputs some gibberish.) You have several choices:
run the database locally, or at least nearby. I mean, it's not a LAMP stack unless it has MySQL. :-) This is what approximately everyone does.
use a tunnel / VPN solution of some kind to get through the firewall and to port 3306
open up 3306 on the firewall. You probably will not get cooperation on this.
Is "skip-name-resolve" option enabled in your my.cnf?

Categories