齐菁记录个人实验过程原创,转载请标明。
在终端中输入:/usr/local/mysql/bin/mysql_config
--libs
注意此处/bin/mysql前面的路径是由mysql的安装路径决定的,通常安装好mysql后会是在这里。
得到的结果,以我的-L/usr/local/mysql/lib
-lmysqlclient -lpthread为例。
把上面得到的结果复制入build
settings 里面的other
linker flags 就可以连接成功了。
把本文附带的文件包解压缩并全部拖入工程,other linker flags需要按照上面输入,通常Header Search
Path与Library Search Path下已经有系统自动寻找到的路径了,若已经存在路径,不要再加入任何东西。
***注意Project与Targets下的路径都需要有且需要相同,若发现其中一个没有的话把另外一个的路径复制粘贴进去。
Sample:
sql:
CREATE TABLE `test` (
`id` int(11) unsigned NOT
NULL AUTO_INCREMENT,
`usrname` varchar(30) DEFAULT
NULL,
`name2` varchar(30) DEFAULT
NULL,
`名字3`
varchar(30) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB
AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;
put the following sentence in .h
#import "MysqlConnector.h"
put the following sentences in .m
//linking with
the server
MysqlServer*
ms=[[MysqlServer alloc]
init];
//linking with
the database
MysqlConnection* mc=[MysqlConnection connectToServer:ms];
//basic
selection
MysqlFetch*
mf=[MysqlFetch
fetchWithCommand:[NSString stringWithFormat:@"select *
from info",nil]
onConnection:mc];
//insert data
MysqlInsert* mi=[MysqlInsert
insertWithConnection:mc];
[mi setTable:@"info"];
[mi
setRowData:@{@"name":@"中文测试21",@"name2":@"中文测试22",@"名字3":@"中文测试23"}];
[mi execute]
关于远程连接mysql:
首先要获得服务器的ip地址,若不是已知,则在终端下使用命令ping
网址来获得其地址,例如:ping hugodynasty.com可以得到23.235.196.252
则输入命令:mysql
-h 23.235.196.252 -u (username) -p(password) -P3306
可以与远程服务器的mysql连接成功。