Develop MySQL database applications in C/C ++ in Linux

Source: Internet
Author: User

I. Mount the optical drive in Linux:

Mount-t iso9660/dev/cdrom/mnt/cdrom

Unmount the optical drive umount/dev/cdrom

The drive eject is displayed.

Push drive eject-t

2. Install MySQL only:

Mysql-server-3.23.54a-11.i386.rpm

Mysql-3.23.54a-11.i386.rpm

Special installation packages are required for MySQL development:

Mysql-devel-3.23.54a-11.i386.rpm


3. Install the Linux package:

Rpm-ivh software package to be installed

Rpm-qa | specific grep Software Package

The software package to be deleted by rpm-e


4. Start the Mysql service in Linux:

/Etc/rc. d/init. d/mysqld status to view the current mysql service status

Service mysqld start mysql service

Mysql-u root-p pass: Use the user name root and password pass to connect to the mysql database


V. MySQL program structure development in Linux C/C ++

Header file: # include

Compilation options:

Gcc-o server. c-I/usr/include/mysql-L/usr/lib/mysql-l mysqlclient-lz-lm

Connection process:

Step 1: connect to the database

Create MYSQL;

Mysql_init (& mysql); Initialization

Mysql_real_connect (& mysql, "hostname", "username", "password", "database", 0, NULL, 0 );

Step 2: Execute SQL statements

Mysql_real_query (& mysql, SQL );

Step 3: Obtain query results

Create a MYSQL_RES structure * res;

Res = mysql_store_result (& mysql );

Step 4: obtain and process each row of the query results

Mysql_fetch_row (res );

Mysql_num_fields (res); number of fields in the result

Printf ("% s \ n", row [index]);

Step 5: release resources

Mysql_free_result (res );

Mysql_close (& mysql );

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.