mysql数据插入效率比较


当前第2页 返回上一页

可以看到:10000次插入使用事务提交只用时4.7秒,而不使用事务用时311秒,拼装成10000次insert语句的耗时7.3秒。这里面耗时7.3秒的,理论上,在数据库sql执行上也应该和使用事务差不多,这里的耗时主要是用作字符串的拼接上,客户端耗时比较多;

贴上测试程序代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data;
using MySql.Web;
using MySql.Data.MySqlClient;
using System.Diagnostics;
using System.Data;
namespace mysqlDEMO01
{
  class Program
  {
    static void Main(string[] args)
    {      
      testInsert();
      Console.ReadLine();
    }
    //使用安全防注入 参数使用@ ,安全插入。
    public static void testInsert()
    {
      List<MySqlParameter> lmp = new List<MySqlParameter>();
      lmp.Add(new MySqlParameter("@pname", "hello2"));
      lmp.Add(new MySqlParameter("@pwd", "1232"));
      string command = " insert into test.testtable(pname,pwd) value(@pname,@pwd); ";
      MySqlInstance.InsertData(command, lmp);
      List<MySqlParameter> lmp2 = new List<MySqlParameter>();
      lmp2.Add(new MySqlParameter("@pname", "hello2"));
      lmp2.Add(new MySqlParameter("@pwd", "1232"));
      MySqlInstance.InsertDataNoTran(command, lmp2);
      test4();
    }
   }
}

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接

更多Mysql内容来自木庄网络博客


标签:Mysql

返回前面的内容

相关阅读 >>

关于mysql触发器的问题

mysql 如何查表数据

mysql查询时间数据

mysql服务启动不了解决方案

学习mysql如何优化查询速度

mysql存储过程是什么意思?

如何理解mysql数据库的优化

为什么不要在mysql中使用utf-8编码方式

详解mysql数据库优化的八种方式(经典必看)

mysql怎么优化

更多相关阅读请进入《mysql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    暂无评论...