MySQL CRUD

How to Insert Multiple Rows in MySQL (With Examples)

Insert multiple rows in MySQL efficiently. Covers multi-value INSERT, INSERT SELECT, LOAD DATA, and batch insert performance tips.

Mar 12, 2026 5 min read

Introduction

Inserting rows one at a time is slow. MySQL lets you insert hundreds or thousands of rows in a single statement, dramatically improving performance.

Insert Multiple Rows with VALUES

The simplest and most common approach — list multiple value tuples in a single INSERT.

-- Insert 5 rows in one statement:
INSERT INTO products (name, price, category)
VALUES
  ('Laptop', 999.99, 'Electronics'),
  ('Keyboard', 49.99, 'Electronics'),
  ('Desk', 299.99, 'Furniture'),
  ('Monitor', 399.99, 'Electronics'),
  ('Chair', 199.99, 'Furniture');

Tip: MySQL can handle thousands of rows in a single INSERT. For very large inserts (100K+ rows), break into batches of 5,000-10,000.

INSERT INTO ... SELECT (Copy from Another Table)

Copy rows from one table to another using INSERT SELECT. Great for data migration and ETL.

-- Copy active users to a new table:
INSERT INTO active_users (id, name, email)
SELECT id, name, email
FROM users
WHERE active = 1;

-- Copy with transformation:
INSERT INTO order_summary (customer_id, total_orders, total_spent)
SELECT
  customer_id,
  COUNT(*) AS total_orders,
  SUM(amount) AS total_spent
FROM orders
GROUP BY customer_id;

Tip: INSERT SELECT is the fastest way to copy data between tables within MySQL — it never leaves the server.

Handle Duplicates with ON DUPLICATE KEY UPDATE

When inserting multiple rows, handle duplicates gracefully with upsert syntax.

-- Insert or update on duplicate:
INSERT INTO products (sku, name, price)
VALUES
  ('SKU001', 'Laptop', 999.99),
  ('SKU002', 'Keyboard', 49.99),
  ('SKU003', 'Monitor', 399.99)
ON DUPLICATE KEY UPDATE
  name = VALUES(name),
  price = VALUES(price);

Tip: ON DUPLICATE KEY UPDATE works with any unique key, not just the primary key.

Bulk Load with LOAD DATA INFILE

For truly massive inserts (millions of rows), LOAD DATA INFILE is 10-20x faster than INSERT statements.

-- Load from CSV file:
LOAD DATA INFILE '/path/to/data.csv'
INTO TABLE products
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(name, price, category);

Tip: LOAD DATA LOCAL INFILE loads from the client machine. LOAD DATA INFILE loads from the server. Use LOCAL for remote connections.

Performance Tips for Bulk Inserts

Maximize insert speed with these proven techniques.

-- 1. Disable indexes during bulk insert:
ALTER TABLE products DISABLE KEYS;
INSERT INTO products ... (thousands of rows);
ALTER TABLE products ENABLE KEYS;

-- 2. Wrap in a single transaction:
START TRANSACTION;
INSERT INTO logs VALUES (1, 'event1', NOW());
INSERT INTO logs VALUES (2, 'event2', NOW());
-- ... hundreds more
COMMIT;

-- 3. Increase bulk insert buffer:
SET SESSION bulk_insert_buffer_size = 256 * 1024 * 1024;

Tip: Single transaction + multi-row INSERT + disabled keys = fastest possible insert in MySQL.

Best Practices

  • Always use multi-row INSERT instead of individual INSERT statements
  • For 100K+ rows, use LOAD DATA INFILE
  • Wrap bulk inserts in a transaction for atomicity and speed
  • Disable keys and re-enable after bulk inserts on large tables
  • Use INSERT IGNORE or ON DUPLICATE KEY UPDATE for data that may contain duplicates

Generate MySQL Queries with AI2SQL

Skip the syntax lookup. Describe what you need in plain English and AI2SQL generates the correct MySQL query instantly.

Try AI2SQL Free

No credit card required

Frequently Asked Questions

How many rows can I insert at once in MySQL?

MySQL has no hard row limit, but the max_allowed_packet setting limits the total query size (default 64MB). For very large inserts, batch into groups of 5,000-10,000 rows.

What is the fastest way to insert data into MySQL?

LOAD DATA INFILE is the fastest (10-20x faster than INSERT). For programmatic inserts, use multi-row INSERT inside a transaction with keys disabled.

Can AI2SQL generate bulk insert statements?

Yes. Describe your data and AI2SQL generates the correct multi-row INSERT or INSERT SELECT syntax.

Generate SQL from Plain English

Stop memorizing syntax. Describe what you need and let AI2SQL write the query for you.

Try AI2SQL Free

No credit card required