默认情况Mysql为提高效率,写数据库是先写到内存,程序关闭或缓存满时才真正写入到数据库,而MSSQL写数据库是即时写入的。
而实际情况应用程序需要即时写入到数据库,避免断电或错误时数据丢失:
Mysql C库函数 mysql_refresh 可将数据库即时更新到数据库
#define SAVE_TABLE(table){\ debug_db("\nsqlstr=\n%s\n",sqlstr);\ ret=mysql_query(&mysql_conn,sqlstr);\ if(ret){\ debug_error("mysql_query %s fails: ",table);\ goto sqlerror;\ }\ \ ret=mysql_affected_rows(&mysql_conn);\ if(ret<=0){\ /*debug_warning("no row be affected in table: %s\n",table);*/\ }\ /*debug_db("%d row be affected in table: %s\n",ret,table);*/\ mysql_refresh(&mysql_conn,REFRESH_TABLES);/*really write to disk*/\ }