C Connect to MySQL database development Xcode environment configuration and testing

Source: Internet
Author: User

First, the development environment


Mac OS X 10.9.2 64-bit, Xcode5.1, MySQL5.5.37 64-bit

The MySQL installation directory is:/usr/local/mysql


Second, configure Xcode to connect MySQL's compilation option


1> Add the MySQL header file directory to the Xcode header file search path

Project Properties--Build Settings--Search Paths, Header search Paths, add /usr/local/mysql/include



2> Adding the MySQL library file directory to the Xcode library file search Path

Project Properties--Build Settings--Search Paths--Library search Paths, add /usr/local/mysql/lib



3> adding link marker options

Item Properties--Build Settings---linking and other Linker flags, add the following markup:

-lmysqlclient

-lm

-lz



4> linking MySQL's dynamic library to the/usr/lib directory

Ln-s/usr/local/mysql/lib/libmysqlclient.18.dylib/usr/lib



Third, test development environment

  main.c//  MySQL database programming////  Created by yangxin on 14-5-22.//  Copyright (c) 2014 yangxin. All rights reserved.//#include <stdio.h> #include <stdlib.h> #include <string.h> #include <mysql.h >mysql mysql;int Main (int argc, const char * argv[]) {    /* before connecting, first use Mysql_init to initialize MYSQL connection handle *    /Mysql_init (& MySQL);        /* Use Mysql_real_connect to connect to the server with parameters such as MySQL handle, server IP address,     login MySQL username, password, database to be connected, etc. *    /if (!mysql_real_connect ( &mysql, "localhost", "root", "Yangxin", "Test", 0, NULL, 0)) {        printf ("Connecting to MySQL error:%d from%s\n", Mys Ql_errno (&mysql), Mysql_error (&mysql));        return-1;    } else {        printf ("Connected Mysql successful!\n");    }        /* Close connection *    /mysql_close (&mysql);    return 0;}

Note:

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.