mysql批量插入BulkCopy的實(shí)現(xiàn)
一、新建項(xiàng)目:SqlSugarDemo
<ItemGroup> <PackageReference Include="SqlSugarCore" Version="5.1.3.52" /> </ItemGroup>
二、連接串未添加AllowLoadLocalInfile=true
中文提示 : BulkCopy MySql連接字符串需要添加 AllowLoadLocalInfile=true; 添加后如果還不行Mysql數(shù)據(jù)庫(kù)執(zhí)行一下 SET GLOBAL local_infile=1
English Message : connection string add : AllowLoadLocalInfile=true
show global variables like 'local_infile'; SET GLOBAL local_infile=1
三、Startup.cs
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace WebApplication3 { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton<ISqlSugarClient>(s => { SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig() { DbType = SqlSugar.DbType.MySql, ConnectionString = "Server=192.168.31.132;User ID=root;Password=123456;Database=sugar;port=3306;AllowLoadLocalInfile=true", IsAutoCloseConnection = true, }, db => { //單例參數(shù)配置,所有上下文生效 db.Aop.OnLogExecuting = (sql, pars) => { }; }); return sqlSugar; }); services.AddControllersWithViews(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); } } }
HomeController.cs
using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using SqlSugar; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using WebApplication3.Models; namespace WebApplication3.Controllers { public class HomeController : Controller { private readonly ILogger<HomeController> _logger; private readonly ISqlSugarClient _sqlSugarClient; public HomeController(ILogger<HomeController> logger, ISqlSugarClient sqlSugarClient) { _logger = logger; _sqlSugarClient = sqlSugarClient; } public IActionResult Index() { _sqlSugarClient.Fastest<RealmAuctionDatum>().BulkCopy(GetList()); return View(); } public List<RealmAuctionDatum> GetList() { var datas = new List<RealmAuctionDatum>(); for (int i = 0; i < 10000; i++) { datas.Add(new RealmAuctionDatum { Name = Guid.NewGuid().ToString("N") }); } return datas; } } }
到此這篇關(guān)于mysql批量插入BulkCopy的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)mysql批量插入BulkCopy內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
mysql 5.7.13 安裝配置方法圖文教程(win10)
這篇文章主要為大家分享了mysql 5.7.13 安裝配置方法圖文教程,感興趣的朋友可以參考一下2016-06-06MySQL-group-replication 配置步驟(推薦)
下面小編就為大家?guī)?lái)一篇MySQL-group-replication 配置步驟(推薦)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-03-03MySQL實(shí)現(xiàn)JDBC詳細(xì)步驟
JDBC?是?Java?訪問(wèn)數(shù)據(jù)庫(kù)的標(biāo)準(zhǔn)規(guī)范,真正怎么操作數(shù)據(jù)庫(kù)還需要具體的實(shí)現(xiàn)類,也就是數(shù)據(jù)庫(kù)驅(qū)動(dòng),本文給大家介紹MySQL實(shí)現(xiàn)JDBC詳細(xì)講解,感興趣的朋友一起看看吧2022-02-02MySQL和Redis的數(shù)據(jù)一致性問(wèn)題
這篇文章主要介紹了MySQL和Redis的數(shù)據(jù)一致性問(wèn)題,下面文章圍繞Redis大的相關(guān)資料展開詳情,需要的小伙伴可以參考一下2022-04-04MySQL的多版本并發(fā)控制MVCC的實(shí)現(xiàn)
MVCC就是多版本并發(fā)控制,本文主要介紹了MySQL的多版本并發(fā)控制MVCC的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12SELECT INTO 和 INSERT INTO SELECT 兩種表復(fù)制語(yǔ)句詳解(SQL數(shù)據(jù)庫(kù)和Oracle數(shù)據(jù)庫(kù)的
我們經(jīng)常會(huì)遇到需要表復(fù)制的情況,如將一個(gè)table1的數(shù)據(jù)的部分字段復(fù)制到table2中,或者將整個(gè)table1復(fù)制到table2中,這時(shí)候我們就要使用SELECT INTO 和 INSERT INTO SELECT 表復(fù)制語(yǔ)句了2019-03-03mysql 5.7.21 解壓版通過(guò)歷史data目錄恢復(fù)數(shù)據(jù)的教程圖解
本文通過(guò)圖文并茂的形式給大家介紹了mysql 5.7.21 解壓版,通過(guò)歷史data目錄恢復(fù)數(shù)據(jù)的方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-09-09