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: