MySQL BULK INSERT
MySQL バルクインサート MySQL 複数データのバルク INSERT や CSV ファイルから高速インポートする方法 【MySQL】LOAD DATA INFILE するときのファイルの文字コード 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 @main.command() @click.argument("source_file") @click.option("--encoding", "-e", default="cp932") @click.pass_context def data_import(ctx, source_file, encoding): """ import TSV file """ opt = get_model()._meta fields = ",".join([f.name for f in opt.fields if f.name not in ["id"]]) SQL = f""" LOAD DATA LOCAL INFILE '{source_file}' INTO TABLE {opt.db_table} CHARACTER SET {encoding} FIELDS TERMINATED BY '\t' ({fields}) ; """ with connection.cursor() as cursor: cursor.execute(SQL) print(cursor.fetchall()) 重複時に UPDATE する(REPLACE): ...