Mysql batch data update and insertion pit

has such a logic, a piece of data, if there is in the database, then update, if it does not exist, then insert. But now there are ten thousand. So how to accomplish the task efficiently?


MySQL has a special syntax INSERT. ON DUPLICATE KEY UPDATE should be the most efficient.
refer to official documentation .

in addition, you have multiple records, so to start a transaction, it is much more efficient to update multiple entries in one transaction than to update one transaction at a time.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3650b-2b857.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3650b-2b857.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?