Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble Connecting To Remote Server's mySQL Database 1

Status
Not open for further replies.

kennygadams

Programmer
Jan 2, 2005
94
US
Hello,

I'm trying to make a mySQL connection from my local server to a remote server but it is not working. What am I doing wrong? Do I need to set some kind of special permissions on the remote server that I'm trying to connect to?

I'm using the following mySQL code in a PERL script to connect to my remote server:
Code:
if($dbh = DBI->connect("DBI:mysql:name_of_database:12.34.56.78", "username", "password")){
    $connected = 'y';
    }
else{
    $connected = 'n';
    }

Best regards,

Kenny G. Adams
 
I don't know about mySQL, but you'll probably need a port assignment and a corresponding open port on the firewalls/routers on both ends and maybe port forwarding, if necessary.

Maybe there is a default port assignment in the config file for mySQL.

Is this secure - like SSH?

Can you ping this remote server?
 
yes, you need to grant rights to remote users on the remote host.


Syntax is

Code:
grant all
on dbname.*
to username@'%'
identifyed by "password"
;

execute a flush privileges statement and try to connect again.

QatQat

If I could have sex each time I reboot my server, I would definitely prefer Windoz over Linux!
 
Thanks.

I ran the following on the command line and the server gave me access from my remote server.

Login to mysql as the root user
Code:
mysql -u root -p
Feedback from server: Enter password:

Enter your root user password:
Code:
XXXXXXXXX
Feedback from server: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12859658 to server version: 5.0.22

Enter the following to give your remote server privileges to access the database:
Code:
GRANT ALL ON database_name_goes_here.* TO username_goes_here@ip_goes_here IDENTIFIED BY 'password_goes_here';
Feedback from server: Query OK, 0 rows affected (0.00 sec)

Best regards,

Kenny G. Adams
- Blog about Boneheads
 
yes, you need to grant rights to remote users on the remote host.

More precisely, you need to grant rights to a remote user/host _PAIR_. The '%' symbol is a wildcard that allows the user to connect from any host. This is deemed (at least by me) a security hazard.

--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
Allowing remote connection on port 3306 is a security risk itself, so I am hoping that the address kennygadams intends to connect from is an internal address and not a public one.
Considering that he needs to cal it from a PHP script I am pretty sure that the DB and the web server are on a LAN.

Anyway, yes you should also specify remote host's address as zelan suggests (you can never be too sure even on a LAN these days!) but stronger restrictions should be applied at firewall level by closing port 3306 if the host is outside your network; I would never rely on the security provided by mysql users' credentials and host settings to allow access from the internet.

A safer way to allow remote connections would be to forward port 3306 using ssh or create a VPN if you need more persistant DB connectivity.

QaTQat




If I could have sex each time I reboot my server, I would definitely prefer Windoz over Linux!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top