|
 |
|
 |
04-18-2005, 04:13 PM
|
#1 (permalink)
|
|
Registered User
Join Date: Apr 2005
Posts: 6
|
Help with outside connection to mysql using a php page
Hi all,
I am having a problem connecting to my "mySQL" server from a computer outside my network.
I have port forwarding setup to goto the right machine on port 3306
firewall allows port 3306 also gave firewall rights to mysqld-nt.exe.
I am running mysql on win 2003 server IIS and PHP
versions.... 4.0.22 mysql 4.3.10 PHP
I put in an IP addy instaed of localhost in the conf.inc.php file as database hostname.... here is the code in that file...
<?
$dbh=mysql_connect ("24.21.XX.XXX:3306", "user", "pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("bytecon_baby");
?>
is this the right connection string? do I need to use a ODBC connection string? (ODbc is setup on the server for that database)
I am stummped.... do i need to give certain users authority to the database directory or the executable? I have given auth. to the internet guest account on these also.
Help please.
Eric
|
|
|
04-18-2005, 07:25 PM
|
#2 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,446
|
the user needs to have rights to access the db from the remote address. as mysql root, you need to run a command something like this:
Code:
GRANT ALL ON bytecon_baby.* to user@1.2.3.4 identified by 'pass';
that is of course if the remote connection was coming from 1.2.3.4 .. if you wanted to allow any ip address to connect using that login, then use '%' as the ip.
Code:
GRANT ALL ON bytecon_baby.* to user@'%' identified by 'pass';
also, on your connect, you don't need :3306 after the ip address. that is the default mysql port and all you would need is the ip.
__________________
Mike
|
|
|
04-18-2005, 08:49 PM
|
#3 (permalink)
|
|
Registered User
Join Date: Apr 2005
Posts: 6
|
I have done all that and still no good on the connection.....
I still get the same error....
grant rights to all ips for that user & database... took out the :3306 in the conf file...
left port forwarding on the router.
any other suggestions?
thanks,
Eric
|
|
|
04-18-2005, 08:51 PM
|
#4 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,446
|
what does the die message say? can you ping the IP from outside?
__________________
Mike
|
|
|
04-18-2005, 09:01 PM
|
#5 (permalink)
|
|
Registered User
Join Date: Apr 2005
Posts: 6
|
Warning: Can't connect to MySQL server on '24.21.98.121' (10060) in D:\Inetpub\temp\wwwroot\126176\aw384aw4\ewd\Questi onnaire\config.inc.php on line 2
Warning: MySQL Connection Failed: Can't connect to MySQL server on '24.21.98.121' (10060) in D:\Inetpub\temp\wwwroot\126176\aw384aw4\ewd\Questi onnaire\config.inc.php on line 2
I cannot connect to the database because: Can't connect to MySQL server on '24.21.98.121' (10060)
Yes i can ping this IP
Thanks
|
|
|
04-18-2005, 09:18 PM
|
#6 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,446
|
well your mysql server can definately be reached from outside. you left your ip address in your reply so i tried to connect. i don't have a valid login, but it let me know 'access denied' which is a good sign. (1.2.3.4 is yoru ip, x.x.x.x is mine)
check it out:
Quote:
]$ mysql -h1.2.3.4 -uuser -p
Enter password:
ERROR 1045: Access denied for user: 'user@x.x.x.x' (Using password: YES)
|
are you sure there is not a firewall on the 'outside server' that is trying to call mysql? it seems like you should be getting the access denied error rather than the cannot connect to server.
__________________
Mike
|
|
|
04-18-2005, 09:30 PM
|
#7 (permalink)
|
|
Registered User
Join Date: Apr 2005
Posts: 6
|
connected fine that way...
there is no firewall installed on the Win 2003 box serving Mysql
I used port forwarding for all calls to port 3306 in my netgear router to point to the IP of the win2003 server.
Firewall on outside server? you mean my win 2003 server?
not sure on that one.
Thanks,
E
|
|
|
04-18-2005, 09:32 PM
|
#8 (permalink)
|
|
Registered User
Join Date: Apr 2005
Posts: 6
|
do you think the ISP may be blocking outbound port3306?
|
|
|
04-18-2005, 09:35 PM
|
#9 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,446
|
i mean on wherever your php scripts that are trying to connect to mysql are.
now, i just noticed something else, .. your mysql_select_db() should take a second argument, $dbh in this case.
try using this code for your connection. of course, replace the variables with your data:
PHP Code:
<?
$hostname="localhost";
$mysql_login="myusername";
$mysql_password="mypassword";
$database="mydatabase";
// connect to the database server
if (!($db = mysql_pconnect($hostname, $mysql_login , $mysql_password))){
die("Can't connect to database server: ".mysql_error());
}else{
// select a database
if (!(mysql_select_db("$database",$db))){
die("Can't connect to database: ".mysql_error());
}
}
?>
__________________
Mike
|
|
|
04-18-2005, 09:37 PM
|
#10 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,446
|
Quote:
|
Originally Posted by ericanca
do you think the ISP may be blocking outbound port3306?
|
not likely since i was able to connect and get an 'access denied' error. that means that i was able to get to the mysql server to give me a response.
__________________
Mike
|
|
|
07-19-2005, 10:15 AM
|
#11 (permalink)
|
|
Registered User
Join Date: Jul 2005
Posts: 1
|
I've been having this same problem, which is what brought me to this thread... And site...
I found one thing that might help. I was having the exact same problem as mentioned in this thread, but I figured something out. Sort of...
If you go into your mysql folder on the computer running MySQL, and go to the "bin" folder. Double click on "winmysqladmin.exe" (or at least that's what it's called for me..). There is a tab called "my.ini Setup". Click that tab.
You will see something that says:
#bind-address=*.*.*.*
(I blocked out the IP address)
Anyway, for me at least, the IP address that was there is different from my current IP address. So, I tried using that instead, and I at least got to the "denied" page instead of the flat out "can't connect" page.
However, here's the problem. The username is being displayed as "root@tricia-pc" (my computer's name) instead of "root@localhost", so I'm getting denied. I tried putting "root@localhost" as the username, but then it came up as "root@localhost@tricia-pc" isntead.
Is there any way to force the username to be "root@localhost"?
Did all that make sense?
Thanks,
Robert
|
|
|
07-19-2005, 10:33 AM
|
#12 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
|
Alter the grant settigns in your mysql access, to reflict your tricia-pc ie:
Code:
GRANT ALL ON <your database>.* to root@tricia-pc identified by 'pass';
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 05:03 AM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|