Project

General

Profile

Connecting to a remote MySql server.

Added by Rajveer Shringi over 8 years ago

Hello

I am using Wt 3.3.5 and MySql 5.4. I have a linux(ubuntu)machine hosting Mysql server and I am trying to access this database via my Wt application. I am not sure how do I provide the login credentials in the connection object. For a local Mysql server this is how my connection object looks like and this works.

    Wt::Dbo::backend::MySQL *connection = new dbo::backend::MySQL("dbName",
                                                                  "root",
                                                                  "password",
                                                                  "localhost",
                                                                  3306,
                                                                  "/var/run/mysqld/mysqld.sock");

Now I try to do the same thing for the remote server via replacing localhost to the remote server name(should it be IP?) that I use for ssh connection to it. I also tried providing the username via user@servername instead of localhost but in this case where do I provide the password?

In the first case when I provide servername instead of localhost I get a connection error - Can not connect to Mysql server. Which makes sense as I did not provide login info.

In the second case when I provide user@servername, it can not resolve the name and error I get is - Cant find Mysql server with this name.


Replies (2)

RE: Connecting to a remote MySql server. - Added by Wim Dumon over 8 years ago

hey rajveer,

can you connect from the machine where you run the dbo application on to the remote mysql server with the command line 'mysql' tool? If so, map the parameters you pass to that command (username, password, host, port, db name, ...) to the parameters of the constructor of the mysql object. Unless I'm mistaken, the socket parameter can be left empty.

Wim.

RE: Connecting to a remote MySql server. - Added by Rajveer Shringi over 8 years ago

Hey Wim

Thanks for the quick response. I havent tried to connect to remote server via command line mysql tool(MySql client), the way I access the database is by first ssh connection to the machine and then using the Mysql client on that machine itself. But I will try to access this via command line mysql tool and post my result.

Rajveer

    (1-2/2)