Last active
September 2, 2020 06:00
-
-
Save ralexandr/18e4648fffd5520f9e5fcde4fd6a900e to your computer and use it in GitHub Desktop.
Non-blocking ALTER TABLE for mySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE `my_awesome_database`.`user_transaction` | |
ADD FOREIGN KEY (`userId`) REFERENCES `my_awesome_database`.`user` (`id`), | |
ALGORITHM=INPLACE, LOCK=NONE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case you get
ALGORITHM=INPLACE is not supported. Reason: Adding foreign keys needs foreign_key_checks=OFF
Run following query before altering your table (it will disable foreign checks only for your current db-connection)
SET SESSION foreign_key_checks=OFF;