MySQL: Skip INSERT / UPDATE statement that triggers error but show them in output
3
votes
1
answer
1327
views
I have a million of rows of customers to be imported via SQL dump. Customer data will be inserted into main table
customer
and child table customer_address
The dump contains the following SQL statements:
**File**: customer-dump.sql
BEGIN TRANSACTION;
INSERT INTO customer (firstname, lastname) VALUES ('John', 'Doe');
INSERT INTO customer_address (customer_id, city, country) VALUES (LAST_INSERT_ID(), 'New York', 'USA');
COMMIT;
BEGIN TRANSACTION;
INSERT INTO customer (firstname, lastname) VALUES ('Lorem', 'Ipsum');
INSERT INTO customer_address (customer_id, city, country) VALUES (LAST_INSERT_ID(), 'Chicago', 'USA');
COMMIT;
# So on for N no of customers
I am importing via CLI as:
mysql -u [user] -p [database] /tmp/customer-import-error.log
**My Queries:**
- How to continue the script execution even if there is a failure in some rows?
- How to show/log errors for failed rows?
- Any advice on such massive import?
Asked by MagePsycho
(201 rep)
Apr 18, 2017, 08:13 PM
Last activity: Jun 27, 2025, 11:08 PM
Last activity: Jun 27, 2025, 11:08 PM