This tutorial covers how we can install MySQL server and MySQL++ API on Ubuntu. The MySQL++ API will help your C++ code to communicate with and retrieve data from your database. So here we go,
To install MySQL Server
Step I:
Go to Terminal and write
$ sudo apt-get install mysql-server
During the installation it will prompt you for the password, set the password and continue (this will be the password of your server)
Step II (Optional):
To be able to connect to mysql from internet, remove the restriction on the configuration file. Open the file by typing the following command at terminal.
$ gksudo gedit /etc/mysql/my.cnf
Find the line bind-address = 127.0.0.1 and comment it out and save the file again.
Like this --> #bind_address =127.0.0.1
Like this --> #bind_address =127.0.0.1
Step III:
Once you're done with the installation, write on terminal
$ sudo apt-get install mysql-query-browser
After installing MySQL Query Browser go to Applications > Programming > MySQL Query Browser
- Now in Stored Connection type: loopback 127.0.0.1
- Enter the password, that you must have set during the step I.
- Click on Connect. Now your mysql server is up.
To install MySQL++
Okay, now we are done with the installation of server, now comes the installation of mysql++, the C++ API which makes your code to communicate with your Database.
Step I:
Go to Terminal and type
$ sudo apt-get update
Step II:
Now, download the required package for mysql++, type.
$ sudo apt-get install libmysqlclient15-dev
Step III:
Now move to home directory and to download .tar file, type
$ cd~
Step IV:
to Untar the file, type
$ tar xvfz mysql++-3.1.0.tar.gz
Step V:
Now configure and Install.
$ cd mysql++-3.1.0
$ ./configure --prefix=/usr
$ make
$ sudo make install
And now your done with the installation of the stuff.
C++ Code to Connect with Database
Here is the c++ code snippet that will help you to connect and communicate with your database.
Sample Code |
Points to remember:
- In the header file, you have to give the complete path, where you've saved your mysql++.h header file, normally this is the case, which has been shown in the above snapshot.
- To compile and run this .cpp file go to terminal and type
$ g++ file_name.cpp -o result -I/usr/include/mysql -lmysqlpp
- To run this file
$ ./result
And you're Done :)
Helpful!
ReplyDeleteNice starter. (Y)
woah !!! ur one elite coder girl :O
ReplyDeleteGood one Aarii =) This would help many.
ReplyDeleteNice support .. thanks a lot your work did 50% of our project..
ReplyDeletewelcome to the Programming world :-)
gg !!
ReplyDeletevery Impressive...!
ReplyDeleteI have found your blog to be quite useful. Keep updating your blog with in valuable information... Regards
ReplyDeleteI definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post."
ReplyDeleteWeb Design
thank you very much!
ReplyDeleteThank you so much!!!
ReplyDeleteWork like a charm!
Hi, I'm looking for a solution to install mysqlc++. I followed every step you suggested but i keep failing the ./configure part. The error log:
ReplyDeletechecking for MySQL library directory... configure: error: Didn't find mysqlclient library in '/usr/lib64 /usr/lib /usr/lib64/mysql /usr/lib/mysql /usr/local/lib64 /usr/local/lib /usr/local/lib/mysql /usr/local/mysql/lib /usr/local/mysql/lib/mysql /usr/mysql/lib/mysql /opt/mysql/lib /opt/mysql/lib/mysql /sw/lib /sw/lib/mysql'
when i use the command:
locate mysqlclient:
/var/cache/apt/archives/libmysqlclient-dev_5.5.32-0ubuntu0.12.04.1_amd64.deb
/var/cache/apt/archives/libmysqlclient18_5.5.32-0ubuntu0.12.04.1_amd64.deb
/var/cache/apt/archives/libmysqlclient18_5.5.32-0ubuntu0.12.04.1_i386.deb
These are the results. It's like there is no client lib... I'm using ubuntu 12.04 64 architecture
Do you have a clue what I'm missing here? Thanks