List:MySQL++« Previous MessageNext Message »
From:Nick Hastings Date:August 17 2009 5:15am
Subject:Re: How to change the way password is given to connect to the
database
View as plain text  
Hi,

* Martin Defeche <martin.defeche@stripped> [090814 22:09]:
> Hello,
> 
> I would like to know if there is way to give the password to connect to the
> database when running the program instead of writing it in the source code.
> 
> In fact, the database is local and the user should be root in order to make
> modification and I want my program to be portable.

In this sort of case I would usually have the program read the users
.my.cnf file.

mysqlpp::Connection c( "somedatabase" );

using the above the users .my.cnf file (/root/.my.cnf since you
specify the user will be root) will be read to obtain the
password.

Or you could specify some other location for the file as follows:

mysqlpp::Connection::set_option( new mysqlpp::ReadDefaultFileOption("/foo/bar/my.cnf" ) );
mysqlpp::Connection c( "somedatabase" );


For information on the .my.cnf file please refer to the standard mysql
client documentation.

Nick.
Thread
How to change the way password is given to connect to the databaseMartin Defeche14 Aug
  • Re: How to change the way password is given to connect to the databaseWarren Young14 Aug
  • Re: How to change the way password is given to connect to thedatabaseNick Hastings17 Aug