Sharing the method of ignoring duplicate data when inserting MYSQL data bitsCN.com
When using the following two methods, the field must be set to "primary key" or "UNIQUE constraint (UNIQUE )".
1: Use replace into (this method uses the replacement method, which is a bit similar to deleting and then inserting)
Replace into Syntax
REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name [(col_name,...)]
{VALUES | VALUE} ({expr | DEFAULT },...), (...),...
Or:
REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name
SET col_name = {expr | DEFAULT },...
Or:
REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name [(col_name,...)]
SELECT...
2: Use INSERT [IGNORE] INTO (this method is highly efficient and can be used to determine whether it exists or not. Otherwise, it will be inserted)
INSERT [IGNORE] INTO Syntax
INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name [(col_name,...)]
{VALUES | VALUE} ({expr [...]
BitsCN.com