MySQLC ++ connection operations in Linux

Source: Internet
Author: User
1. the mysql-client package needs to be installed on the client, and the library file we need after installation; 2. Install the mysql-dev package. After installation, we need mysql. h file; 3,

1. the mysql-client package needs to be installed on the client, and the library file we need after installation; 2. Install the mysql-dev package. After installation, we need mysql. h file; 3,

1. the mysql-client package needs to be installed on the client. The library files we need after installation are complete;

2. Install the mysql-dev package. After installation, we need the mysql. h file;

3. As a client, you only need to install these two packages:

The following is a simple test code:
# Include
# Include
Int main ()
{
/* Declare ures and variables */
MYSQL mysql;
MYSQL_RES * result;
MYSQL_ROW row;
// Initialize MYSQL structure
Mysql_init (& mysql );
// Connect to database
// Mysql_real_connect (& mysql, "localhost", "root", "nriet", "test", 0, NULL, 0 );
Mysql_real_connect (& mysql, "192.168.13.27", "root", "nriet", "nriet", 0, NULL, 0 );
// Execute query
Mysql_query (& mysql, "select * from test ");
// Get result set
Result = mysql_store_result (& mysql );
// Process result set
While (row = mysql_fetch_row (result )))
{
Fprintf (stdout, "% s-% s \ n", row [0], row [1]);
}
// Mysql_query (& mysql, "insert into test values (3, 'A ')");
// Clean up
Mysql_free_result (result );
Mysql_close (& mysql );
}

4. "Libraries" under "gcc c ++ Linker ":

Libraries (-l): mysqlclient
Libraries search path (-L):/usr/lib/mysql
Then we can make it a success !!

,

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.