我试图将本地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))");但最后,我在该行上得到了一个语法错误。当我不断收到权限错误时,我不知道如何将这个文件插入我的数据库。
发布于 2016-11-17 01:53:19
进入mysqladmin并运行
mysql> use mysql;
mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON yourdb.* TO james@localhost IDENTIFIED BY 'yourpassword';
mysql> FLUSH PRIVILEGES;
mysql> \q只要您与来自localhost的james连接,您就应该拥有对数据库中所有表的权限。
https://stackoverflow.com/questions/40645275
复制相似问题