tags:

views:

296

answers:

4

Howdy everyone!

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.

A: 

MySQL user depends on the computer it is access from. 'root@localhost' is not the same root as '[email protected]'. 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 '[email protected]' to the MySQL server and don't forget to set the privilege for that user to access to the database needed.

Hope this helps

NawaMan
but the error doesnt look like its login issue. It should connect to the sql server first
Shoban
he hasn't got far enough to have a login issue, he isn't even connected
DigitalRoss
A: 

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.
DigitalRoss
Hi Ross,Thanks for your thoughts. And you'll have to forgive my greenhorn position on these matters; I'm a PHP developer that's always had my environments served up to me on a silver platter. :)Ideally, I would be running my apps locally on the LAMP stack. However, the University has just decided to go with a .Net CMS that is hosted offsite. Our IT folks have decided to keep my LAMP environment separate from the server running the CMS. As such, I can't run my php scripts locally.Justin
Justin
+1  A: 

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.
Vinko Vrsalovic
Unknown MySQL server host 'mysqlserver.edu' says it all really, your webservice can not resolve mysqlserver.eduFix that
Anti Veeranna
When I use the IP address I get the following error instead:Warning: mysql_connect(): Can't connect to MySQL server on 'xxx.xxx.xxx.xx' (4) in /home/content/x/x/x/xxxxx/html/testconnect.php on line 3Can't connect to MySQL server on 'xxx.xxx.xxx.xx' (4)Adding more details...I need to be on either the local university network or use a VPN to access https://schoolsite.edu. I'm not knowledgeable to know what that means. :(Justin
Justin
Okay, that confirms the problem. You need to talk to your admin so he can tell you how to connect the machine to the VPN. What seems more sensible to me is that you have a local copy of the database while you develop and then deploy the system on one of the local machines...
Vinko Vrsalovic
A: 

Is "skip-name-resolve" option enabled in your my.cnf?

shantanuo