c 中mysql插入数据_shell、C中mysql插入数据语句

#!/bin/bash

HOSTNAME="192.168.209.43"

PORT="3306"

USERNAME="root"

PASSWORD="123456"

DBNAME="operation_monitor"

TABLENAME="error_log"

create_db_sql="create database IF NOT EXISTS ${DBNAME}"

mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${c    reate_db_sql}"

insert_sql="insert into ${TABLENAME} values('billchen',2)"

mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${in    sert_sql}"

MYSQL mysql,*sock;

mysql_init(&mysql);

if ( !(sock=mysql_real_connect( &mysql,"127.0.0.1","root","123456","operation_monitor",3306,NULL,0)))

{

fprintf(stderr,"Couldn't connect to engine!\n%s\n\n",mysql_error(&mysql));

printf(" connect mysql error!\n");

exit(1);

}

sprintf(record_day_time,"%d%d",record_time,record_time_day);

sprintf( ibuf,"insert into error_log(id,function_name,description,record_time) values('','%s','%s','%s')",function_name,description,record_day_time);

//exit(0);

if ( mysql_query(sock,ibuf))

{

printf("insert data error!i No.%d\n",lines);

}

else

{

;

}

mysql_close(&mysql);

mysql_close(sock);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值