MySQL below c connect MySQL database

Source: Internet
Author: User

1. Installing the sudo yum install Mysql-devel installation components and libraries

2.

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <mysql/mysql.h>int main ( int argc, const char *argv[]) {    mysql mysql;    Mysql_res *result;    Mysql_row ROW;    Mysql_init (&mysql);    Mysql_real_connect (&mysql, "127.0.0.1", "SYSWJ", "123456",                        "Sysdb", 0, NULL, 0  );    mysql_query (&mysql, "select * from Stu");    result = Mysql_store_result (&mysql);    while (row = mysql_fetch_row (result))    {    printf ("%s%s%s  %s  %s\n", row[0], row[1], ROW[2], row[3], row[4], row[5]);    }   Mysql_free_result (result);   Mysql_close (&mysql);    return 0;}

3. Compilation: GCC test-l/usr/lib/mysql-lmysqlclient

4. Implementation:

[Email protected] document]$/a.out 950 li  Yong  m CS951  Zhang San  F EN952 John Doe  F  -  DC953  will be  large  f  DC954  can be  large  m  CS955  Hello  F  27  

Reference: http://www.linuxidc.com/Linux/2011-12/49133.htm



MySQL below c connect MySQL database

Related Article

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.