#!/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);