用gcc批次建mysql庫表(轉)

subid發表於2007-08-12
用gcc批次建mysql庫表[@more@]作 者: 陳景峰


file 1

my.c
//--------------------------------------------------------
// MySQL Database Create 1/13/2001. Netkiller Chen
//--------------------------------------------------------
#include
#include
main()
{
char host[16]; //mysql host address.
char sid[15]; //root user name.
char pwd[15]; //root password.

/* char *table_file[]={
"gsxx",
"bcxx",
"fgxx",
"hmbxx",
"ltxx",
NULL
};*/
//char *mysql;
char mydatabase[256];
char mysqltable[256];
int i;
int max_table_num;
int db,status;
i=0;
max_table_num=4; //max_table_num

system("clear");
showme();printf(" ");

printf("MySQL host:");scanf("%s",host);
printf("Root user:");scanf("%s",sid);
printf("Password:");scanf("%s",pwd);
printf("Loading........ ");
while(table_file[i]){
sprintf(mydatabase,"echo "create database %s"|mysql -h%s -u%s -p%s",table_file[i],host,sid,pwd);
sprintf(mysqltable,"mysql -h%s -u%s -p%s %sdb=system(mydatabase);
status=system(mysqltable);
// printf("%s %s",mydatabase,mysqltable);
printf(table_file[i]);
//printf("%d",status);
if(db==0 && status==0){
printf(" Install [ OK ] ");
}else{
printf(" Install [ :( ] ");
}
i++;
}
address();
}


//------------------- Function ------------------
showme()
{
printf("------------------------------------------------------------------- ");
printf(" I am Netkiller Chen. ");
printf(" I am a programmer and system&net manager. ");
printf(" I am glad to be friend with you! ");
printf("------------------------------------------------------------------- ");
}
address()
{
printf(" ---------------------------------- ");
printf("| newtech@sina.com | ");
printf("| OICQ:13721218 | ");
printf("| 1/13/2001 | ");
printf("---------------------------------- ");
}


file 2
table.h
char *table_file[]={
"alxx",
"bcxx",
"fycx",
"fyxwxx",
"fyzxxx",
"hwzx",
"lhzxxx",
"xxdexx",
"xxdsxx",
"xxfgxx",
"xxglxx",
"xxgsxx",
"xxhmbxx",
"xxhtxx",
"xxjbxx",
"xxltxx",
"xxzwxx",
"xxzx",
NULL
};
些程式可以方便建表。。。有什麼不明白與我聯絡。
程式隨算不上什麼。。。。。但也解決了一些批次建表的問提。
這個程式可以做為gcc剛入門愛好的參考,因為這個程式象hello world一樣間簡單。而且很全包括了指標,陣列,檔案包含,NULL

使用者方法兩個檔案置於。/root/mygcc/下,將預建庫mysql語句檔案,檔名命名為xxxx.sql同上然後
#gcc my.c -o my
#my
即可。。。不用我在說了吧?


---陳景峰(netkiller)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10796304/viewspace-952500/,如需轉載,請註明出處,否則將追究法律責任。

相關文章