Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top