views:

128

answers:

2

I am accessing a MySQL database within a C++ app using MySQL C++ Connector. It works fine if I have the C++ and the MySQL on the same machine. So, something like the following code works fine:

sql::Connection             *_con;
sql::mysql::MySQL_Driver    *_driver;
_driver = sql::mysql::get_mysql_driver_instance();
_con = _driver->connect("tcp://127.0.0.1:3306", "user", "password");

However, I can't seem to access the database if it is located on another machine. So, something like this:

sql::Connection             *_con;
sql::mysql::MySQL_Driver    *_driver;
_driver = sql::mysql::get_mysql_driver_instance();
_con = _driver->connect("tcp://somesite.com:3306", "user", "password");

Is it just not possible or am I doing something wrong?

+1  A: 

I have done this through a VPN so I am assuming it is possible. Are you using the correct port?

Mark Callison
I'm using the same port and I port forward from the router to the machine with the MySQL db. I tried with both machines on the same LAN and use the LAN's IP address, e.g. 192.168.0.2. That didn't work either.
zooropa
+2  A: 

Did you accidentally setup your users so that they can only access your DB from the local machine?

Did you do

create user 'user'@'127.0.0.1' ...

or

create user 'user'@'%' ....

If you did the first then you won't be able to log on from a different machine.

Did you also grant the privileges correctly?

See the MySQL docs for a more in depth explanation on how to do this correctly

Glen
This worked! Thanks!
zooropa