I have a remote mysql database server setup on a machine myuniversity.edu
and server is named 'localhost
'. On it I have the database named 'MyDatabase
'.
I want to connect it through Java.
The connection urls that I have tried are:
jdbc:mysql://myuniversity.edu/localhost
jdbc:mysql://myuniversity.edu/localhost/MyDatabase
jdbc:mysql://myuniversity.edu:3306/MyDatabase
but I get the `Connection refused: connect` exception.
Could someone please tell what the connection url should be in this case?
localhost
or127.0.0.1
refers to your current computer (there even are jokes about it, like this). The name of the server must bemyuniversity.edu
. If it's not available through your network like that, try using it's IP (something like10.0.0.15
) – Luiggi Mendoza Feb 20 '13 at 6:28myuniversity.edu
is a domain name so to access your mysql remotely you either need to know a domain name (e.g.server
) of a machine where mysql is running and then use the full domain name (e.g.server.myuniversity.edu
) or you need to know an IP address of that machine. You can uselocalhost
only to connect to local (on the same machine) instance of mysql. – peterm Feb 20 '13 at 6:28hostname
command, and you can find its IP address by listing the interfaces (network cards) usingifconfig -a
– Andrew Alcock Feb 20 '13 at 6:34jdbc:mysql://theipaddress:3306/MyDatabase
but I get the same error.I checked the bind-address in my.cnf file and it's 127.0.0.1
Could you please tell me if it should be the ip address of the host? – neeraj narang Feb 20 '13 at 7:53