could not connect . please help . newbie question :)

trung posted 9 years ago in General

my school provide me a user name and pw to access to the school mysql database.

i run a php test code similar to this and it connect ok. I load the php code up to some website and it connected this way.


//Global variables:
$username = ""; // Username for database here
$password = ""; // Password for database here
$db_host = "localhost"; // DB Server
$db_name = ""; //name of your database here

// Connect to DB
or die("Unable to connect to SQL server!");
or die("Unable to select database!");

echo "Connection established to $db_name";


But when i try to connect using HeidiSQL. I could not connect. I ask the school about port number they said 3306. but i still can't connect from HeidiSQL. (i got HeidiSQL connect to localhost fine, so it is working)

Please let me know what did i miss? is there a block at my school or what do i need to do so i can connect

ansgar posted 9 years ago
> $db_host = "localhost"; // DB Server

I guess the website's localhost is the same host where the mysql server is running. HeidiSQL runs from your "desktop host", so you cannot use localhost to reach a remote server. You have to use the public hostname or ip address in HeidiSQL.
trung posted 9 years ago
i use my school: host address and password of course. this code is just example cause i can't give out all the info here :)

my point is i know the database is listenting there and i can connect using that php connect testing file. when i post this php file it stated connected.

it just i can't connect using the HeidiSQL . i just wonder if i miss anything.
ansgar posted 9 years ago
If you are really sure about typing the correct hostname and that there aren't any firewall rules blocking your connection then it is obviously the MySQL server not allowing external connections - see the "skip-networking" option in my.ini on the server.

If you have control over the mysql server: change that setting to 0, restart the mysql server and Heidi should be able to connect.
rosenfield posted 9 years ago
You can use TCP SYN tracerouting...:

- Download for example http://tracetcp.sourceforge.net/.
- Specify your school server's hostname and port 3306.

... to find out which host along the way blocks or drops the connection attempt.

You will get either a reject (TCP RST or ICMP unreachable) at some point along the way. Or a timeout (packets dropped) in which case all subsequent trace lines in the output will be timeouts.

Compare it to a traceroute that goes through (eg a normal ICMP/UDP traceroute) and see if the supposed next host, where the connection attempt dies, happens to correspond to your school's firewall.

Can you SSH to the server? In that case it's very easy to setup a tunnel running over the SSH connection.
trung posted 9 years ago
I check with my university department. it is correct port. and i can only connect to the shool mysql system at my university.

I guess they only allow log in using GUI for certain place to avoid hacker?

is it normal that the my school do that for security reason? cause i can connect using Heidi GUI fine when i am at school. but other place i can not.

i just dont want to ask the IT people from school, they are not very nice :)

thanks for all the help.
rosenfield posted 9 years ago
Yeah, that's perfectly normal.

For schools, you can usually get in via something like SSH, and it's pretty easy to make a tunnel via SSH, so try taking a look at that..

Please login to leave a reply, or register at first.