MySQL 一次执行多条语句的实现及常见问题
代码如下:
//链接时设定
mysql_real_connect( ..., CLIENT_MULTI_STATEMENTS );
//或者
//中途指定
mysql_set_server_option( mysql, MYSQL_OPTION_MULTI_STATEMENTS_ON ); //mysql是连接的名称
当使用执行多语句功能后,一定要读完整个resault集,否则会出现错误:Commands out of sync; you can't run this command now
官方推荐的执行语句是这样的:
复制代码
代码如下:
do
{
/* Process all results */
...
printf( "total affected rows: %lld", mysql_affected_rows( mysql ) );
...
if( !( result mysql_store_result( mysql ) ) )
{
printf( stderr, "Got fatal error processing query\n" );
exit(1);
}
process_result_set(result); /* client function */
mysql_free_result(result);
}while( !mysql_next_result( mysql ) );
如果仅仅是插入等不需要返回值的SQL语句,也一样得读完整个resault集并释放,最小化的写法:
复制代码
代码如下:
do
{
result = mysql_store_result( mysql );
mysql_free_result(result);
}while( !mysql_next_result( mysql ) );
相关文档:
郁闷!CSDN的博客编辑器右边怎么没有显示出来完啊,搞个什么“如何使用客户端写博客”,害我输入的字都被那个提示挡住了!
转入正题:
今天一大早起来,打开eclipse启动tomcat,昨晚还正常运行的一个项目却报错,给我的心情真是一个打击呀~~新年第一天就不太顺利!
经过检查才知道使用的数据库mysql没有启动, ......
一直习惯使用小写的SQL保留字,没想到今天居然遇到了麻烦哈!!和谐一下MYSQL啦!
环境:Server version: 5.1.37-1ubuntu5 (Ubuntu)
alter table child_table_name
add constraint constraint_name
foreign key (column_1)
references reference_table_name(reference_column_1);
和
ALTER TABLE child_t ......
使用mysql时,通常表中会有一个自增的id字段,但当我们想将表中的数据清空重新添加数据时,希望id重新从1开始计数,用以下两种方法均可:
方法一:
alter table tablename drop column id;
alter table tablename add id mediumint(8) not null primary key auto_increment first;
方法二:
alter table tab ......
地址: http://imysql.cn/taxonomy/term/1?page=1
[InnoDB系列] -- innodb表如何更快得到count(*)结果:http://imysql.cn/2008_06_24_speedup_innodb_count
[InnoDB系列系列] -- 大数据量的导出导入方法比较:
http://imysql.cn/2007_10_15_large_innodb_table_export_import
[MySQL优化案例]系列 -- DISABLE/ENABLE K ......