Html文件没有插入Mysql表

时间:2016-11-17 01:30:24

标签: html mysql c

我试图插入本地html文件' test.html'进入mysql中的一个表,我通过嵌入式c代码在mysql服务器上工作。但是,当我尝试插入该html文件时,我收到了拒绝访问错误。

void clrstr(char *buf){
    buf[0] = '\0';
}
int main(int argc, char *argv[]) {
    MYSQL mysql;
    MYSQL_RES *res;
    MYSQL_ROW row;
    MYSQL_FIELD *field;
    char query[MAX_QUERY];
    int x;
    int i = 0;

    char *records[] = {
        "LOAD DATA INFILE 'test.html' INTO TABLE students"};

    mysql_init(&mysql);
    mysql_options(&mysql, MYSQL_READ_DEFAULT_GROUP, "mydb");
    if (!mysql_real_connect(&mysql, HOSTNAME, USERNAME, PASSWORD,
        DATABASE, 0, NULL, 0)) {
       error("Could not connect to host.",&mysql);
    }

    clrstr(query);
    /* varchar max*/
    strcat(query, "create table students (id int not null auto_increment, fileaa text(65535),primary key(id))");

    printf("Creating students table.\n");

    /*
        Create students table
    */
    if(mysql_query(&mysql, query)){
      error("Could not create table!",&mysql);
    }

    clrstr(query);

    /*
        Insert a records into the students table
    */

    printf("Inserting students.\n");

    for(x = 0; x < 1; x++){
        if(mysql_query(&mysql, records[x])){
            printf("Failure to insert: %s\n",records[x]);
            error("Could not insert record",&mysql);
        }
    }

    clrstr(query);

    /*
        Let us look at what we inserted
    */
    strcpy(query, "select * from students order by last_name");

    if(mysql_query(&mysql, query))
      error("failed select 1",&mysql);

    /*
        Store results from query into res structure.
    */
    if (!(res = mysql_store_result(&mysql))){
        error("failed store 1",&mysql);
    }

    /*
        print all results
    */
    while ((row = mysql_fetch_row(res))) {
        for (i=0; i < mysql_num_fields(res); i++){
            printf("%s ", row[i]);
        }
        printf("\n");
    }

    /*
        Drop the students table
    */

    strcpy(query, "drop table students");

    if(mysql_query(&mysql,query))
      error("fail drop 1",&mysql);

    /*
        Finally close connection to server
    */
    mysql_close(&mysql);

    printf("All done\n");

    return 0;
}

我尝试在此行添加以下行:GRANT FILE ON *.* TO 'james'@'localhost'

 strcat(query, "GRANT FILE ON *.* TO 'james'@'localhost',create table students (id int not null auto_increment, fileaa text(65535),primary key(id))");

然后我最终在该行上获得语法错误。当我不断收到权限错误时,我不确定如何将此文件插入到我的数据库中。

1 个答案:

答案 0 :(得分:0)

进入mysqladmin并运行

secureObject

只要您从localhost连接为james,就应该拥有数据库中所有表的权限。