Mysql – how to add key and UNIQUE KEY to existing table without check to speed up performance

foreign keyMySQLmysql-5.6

i have very big InnoDB tables in MYSQL 5.6 version , i want to add KEY an UNIQUE KEY as fast as i can , the data is from restored database so all keys are checked , i am looking something like SET FOREIGN_KEY_CHECKS=0; in FOREIGN KEY . is there something like this for keys ?

Best Answer

If I understand correctly, you want to achieve improved performance for the restore process of an SQL dump file. In that case, you can use do SET UNIQUE_CHECKS=0; before inserting the data and then SET UNIQUE_CHECKS=1; afterwards.

(mysqldump already does this automatically, at least for MariaDB.)

See also the documentation for bulk loading data.