我的mysql安装路径是C:\Program Files\MySQL\MySQL Server 5.5数据存储路径是D:\Data\data
File 'C:\mysql\\share\charsets\?.conf' not found (Errcode: 2)
Character set '#33' is not a compiled character set and is not specified in the
'C:\mysql\\share\charsets\Index' file
the database is not exist!
查看my.ini中路径配置是对的
下面是代码
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include"mysql.h"          //mysql头文件MYSQL mysql;               //初始化
MYSQL_RES *result;
MYSQL_ROW row;
insert_rows_into_student_table(){
    char csage[]="18";
char issex[]="m";
char isno[]="95002";
char isname[]="xxxxxx";
char isdept[]="cs";
char strquery[100]="insert into student(sno,sname,sage,ssex,sdept) values('";
char yn[2];
while(1){
    printf("sno(eg:95001):");
scanf("%s",isno);
strcat(strquery,isno);
strcat(strquery,"','");
printf("name(eg:xxxx):");
scanf("%s",isname);
strcat(strquery,isname);
strcat(strquery,"','");
printf("age(eg:18):");
scanf("%s",csage);
strcat(strquery,csage);
strcat(strquery,"','");
printf("sex(eg:m^w):");
scanf("%s",issex);
strcat(strquery,issex);
strcat(strquery,"','");
printf("dept(eg:cs):");
scanf("%s",isdept);
strcat(strquery,isdept);
strcat(strquery,"');");
if(mysql_query(&mysql,strquery)==0){
    printf("execute successfully!%d\n\n");
}
else{
    printf("error:execute%d\n");
}
printf("inser again?(y^n):");
scanf("%s",&yn);
if(yn[0]=='y'||yn[0]=='Y'){
    continue;
}
else break;
}
return 0;
}
int main(){
    int num=0;
int choice;
mysql_init(&mysql);
if(mysql_real_connect(&mysql,"localhost","root","root","xxgl",3306,0,0))
{
   
   
       for(;;){
       printf("sample embedded sql for c application\n");
   printf("please select one function to execute:\n\n");
   printf("0--exit||1--创建学生表");
   printf("\n");
   scanf("%d",choice);
   switch(choice){
    case 0: exit(0);break;
case 1: insert_rows_into_student_table();break;
default:printf("error input!\n");break;
   }
   }
   
  
}
else
{
printf("the database is not exist!");
}
mysql_close(&mysql);
return 0;
}

解决方案 »

  1.   

    没成功吗?提示什么?
    你先执行一条简单的语句如“select 1”你的配置中,有未开启的项
      

  2.   

    编译之后不会报错,出现下面的提示:感觉说少了文件'C:\mysql\\share\charsets\?.conf' not found
    于是我先在c盘那建了相应的文件,但是错误会变成 Errcode: 22
    我的mysql装在c盘programfile下面
    可能是装错地方了吧,我现在装在d:\mysql\..\ 现在就不会报上面的错了