Skip to main content

mysql_bulk_insert

Function mysql_bulk_insert 

Source
pub async fn mysql_bulk_insert(
    conn: &mut SqlxMySqlConnection,
    table: &str,
    columns: &[&str],
    rows: &[Vec<Value>],
) -> Result<u64, DbError>
Expand description

MySQL 批量导入(多行 INSERT,作为 LOAD DATA LOCAL INFILE 的安全替代)

构建多行 INSERT 语句:INSERT INTO t (c1, c2) VALUES (?, ?), (?, ?), ... 使用参数绑定避免 SQL 注入。MySQL 原生支持 ? 占位符。 当数据量极大时建议分批调用(每批 1000~10000 行),避免 SQL 过长或超出 max_allowed_packet 限制。