Ubuntu under C + + connection MySQL Database

Source: Internet
Author: User

Refer to the blog's approach: http://zhmy.michael.blog.163.com/blog/static/861578792012101244715692/

1. Installing Mysql:sudo apt-get Install Mysql-server

2. sudo apt-get install libmysql++-dev

3. Copy lib:

sudo cp/usr/lib/mysql/plugin/usr/lib/-A

4. You can try it.

Create a new CPP file with the following code:

  1  #include <iostream> 2  # Include <mysql/mysql.h> using  Span style= "color: #0000ff;" >namespace   Std;    5  int   Main ()   6     {  7    mysql_init (&mysql);   return  0   10 } 
View Code

The library must be added when compiling, the command is as follows:

sudo g++-o test Test.cpp-l/usr/lib/mysql-lmysqlclient-lz

Then./test runs, and this code doesn't do anything, but if the code compiles successfully, then the rest is fine.

If you do not add the following arguments, the Mysql_init error is not found.

Ubuntu under C + + connection MySQL Database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.