- Download the latest tar from http://dev.mysql.com/downloads/mysql/
You should end up with something like: mysql-connector-c-6.1.2-osx10.7-x86_64
- Drag
libmysqlclient.ainto your project
Inside the lib folder, you'll see the file libmysqlclient.a. Drag that from the finder into your project, and include it in the Target (main app)
- Drag
mysql.hand other header files into your project
Working through compiler errors, I determined that these are the required files, some of which are in include, include/mysql, and include/mysql/psi:
psi_base.hpsi_memory.hmy_alloc.htypelib.hplugin_auth_common.hmysql.hmysql_com.hmysql_time.hmysql_version.hclient_plugin.hmy_list.h
- Add
libc++.dylibto your project.
Click on the topmost item of the project, so you can select your application target. In "Linked Frameworks and Libraries", click the + button, and search for libc++.dylib. In the confirmation, make sure the target is selected.
- Add 4
MySQLKit*.*files to your project.
Drag them into XCode from the finder:
MySQLKitDatabase.hMySQLKitDatabase.mMySQLKitQuery.hMySQLKitQuery.m
- Implement your own database code somewhere
MySQLKitDatabase* db = [[MySQLKitDatabase alloc] init];
db.socket = @"/tmp/mysql/mysql.sock";
db.serverName = @"localhost";
db.dbName = @"sampledb";
db.userName = @"root";
db.password = @"12345";
db.port = 8889;
@try{
[db connect];
MySQLKitQuery *query = [[MySQLKitQuery alloc] initWithDatabase:db];
query.sql = @"select * from table1 order by id";
[query execQuery];
NSInteger len = query.recordCount;
for(NSInteger i = 0; i < len; i++){
NSInteger id1 = [query integerValFromRow:i Column:0];
NSString *stringV1 = [query stringValFromRow:i Column:1];
//...
}
}
@catch (NSException *exception) {
// ...
[db errorMessage];
}- You should be off to the races now!
Note: credit to http://macbug.org/macosxsample/mysql for helping get us off the ground!