Linux下C连接MySQL数据库方法:
- #include<stdlib.h>
- #include<stdio.h>
-
- #include<mysql.h>
-
- int main(int argc,char* argv[])
- {
- MYSQL *conn_ptr;
-
- conn_ptr = mysql_init(NULL);
- if(!conn_ptr){
- fprintf(stderr,"mysql_init failed
");
- return EXIT_FAILURE;
- }
-
- conn_ptr = mysql_real_connect( conn_ptr, "localhost", "li", "li","mysql", 0, NULL, 0 );
-
- if(conn_ptr){
- printf("Connection success
");
- }else{
- printf( "Connection failed
");
- }
-
- mysql_close( conn_ptr );
-
- return 0;
- }
编译方法:????????gcc $(mysql_config --cflags) xxx.c -o xxx $(mysql_config --libs)方法二:gcc test.c -o test -L/user/lib/mysql -lmysqlclient 成功!方法三:gcc test.c -o test $(mysql_config --cflags) $(mysql_config --libs)或者:gcc test.c -o test $(mysql_config --cflags --libs) 成功!创建hr用户和表Oracle入门之表管理相关资讯 Linux c MySQL基础教程
- Linux C 内存管理方式之半动态 (08月05日)
- Linux C语言中gotoxy函数 (04月11日)
- Linux系统中C&Cpp程序开发 (04月01日)
| - Linux C动态内存泄漏追踪方法 (08月04日)
- 关于Linux下conio头文件的实现 (04月11日)
- Linux C 实现mysleep函数 (03月14日)
|
本文评论 查看全部评论 (0)