浏览文章

文章信息

Mysql使用ON DUPLICATE KEY + AUTO INCREMENT issue mysql解决办法 404

1)将表引擎设置为

ENGINE=MyIsam;
2)联合执行
SET @NEW_AI = (SELECT MAX(`the_id`)+1 FROM `table_blah`);
SET @ALTER_SQL = CONCAT('ALTER TABLE `table_blah` AUTO_INCREMENT =', @NEW_AI);
PREPARE NEWSQL FROM @ALTER_SQL;
EXECUTE NEWSQL; 
INSERT INTO `table_blah` (`the_col`) VALUES("the_value")
ON DUPLICATE KEY UPDATE `the_col` = "the_value";

原创