简体   繁体   中英

Is MySQL C++ Connector access to remote database possible?

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM