This post has already been read 5447 times!

MySQL++ is a C++ wrapper for MySQL’s C API. It is built around the same principles as the Standard C++ Library, to make dealing with the database as easy as dealing with STL containers. In addition, MySQL++ provides facilities that let you avoid the most repetitive sorts of SQL within your own code, providing native C++ interfaces for these common tasks.

Check this web page and download the latest source code:

mysql++-3.2.1.tar.gz (2.2 MB, 2013.12.10) — Library source code

tar xvfz mysql++-3.2.1.tar.gz
cd mysql++-3.2.1.tar.gz
make install

After mysql++ installation you will see the following message :

sudo make install
mkdir -p /usr/local/lib
/usr/bin/install -c -m 644 /usr/local/lib
/usr/bin/install -c /usr/local/lib
(cd /usr/local/lib ; rm -f; ln -s; ln -s
mkdir -p /usr/local/include/mysql++
(cd . ; /usr/bin/install -c -m 644  lib/*.h /usr/local/include/mysql++)

For a easy use of MySQL++ I sugest to make the following operations :

1. Copy the mysql++ from /usr/local/include/mysql++ to /usr/include/mysql++

sudo cp -r /usr/local/include/mysql++ /usr/include

2. Copy the from /usr/local/lib to /usr/lib64(for x86_64 configurations)

sudo cp * /usr/local/lib /usr/lib64

3. Then use MySQL++ in C++ with Eclipse with the following settings :

C/C++ Build->Settings->GCC C++ Compiler->Includes
Include paths (-l)


C/C++ Build->Settings->GCC C++ Linker->Libraries
Library search path(-L)


C/C++ Build->Settings->GCC C++ Linker->Miscellaneous
Linker flags : -lmysqlpp -lmysqlclient
Other options(-Xlinker [option])


I post here a little example with a MySQL++ connexion made in Eclipse with the required settings.

#include <iostream> 
#include <mysql++.h>
#include "database.h"

using namespace std;
using namespace mysqlpp;
using namespace Database;

int main(int argc, char* argv[]) {

	// create the database object
	MW_DATABASE database;

	if( database.connectDatabase("database","localhost","root","",3306) )
		cout << "Database connexion SUCCESS..." << endl;
	else {
		cout << "Database connexion error" << endl;

	return 0;


namespace Database {

	class MW_DATABASE {

		protected :
			bool connected;
			unsigned int port;
			const char* host;
			const char* database;
			const char* username;
			const char* password;

		public :
			bool connectDatabase(const char* database, const char* host, const char* username, const char* password, unsigned int port);

	}; //end class MW_DATABASE

}//end namespace Database


#include <iostream>
#include <errno.h> 
#include <mysql++.h>
#include "database.h"

using namespace std;
using namespace mysqlpp;

namespace Database {

	bool MW_DATABASE::connectDatabase(const char* database, const char* host, const char* username, const char* password, unsigned int port){

		bool thereturn;

    	try {
    		Connection conn(use_exceptions);
    		thereturn = conn.connect(database, host, username, password, port);

        // Handle any query errors
    	catch (const BadQuery& er)
	        cerr << "Query error : " << er.what() << endl;
	        thereturn = false;

	    // Catch-all for any other MySQL++ exceptions
	    catch (const Exception& er) {
	        cerr << "MySQL++ error : " << er.what() << endl;
	        thereturn = false;

		return thereturn;
	}//end method connectDatabase

}//end namespace Database

The sources for MySQL++ project with Eclipse

Comments are closed.

Post Navigation