- Table of contents
- MySQL queries
MySQL queries¶
DB admin¶
Rename database¶
sudo -s service mysql stop cd /var/lib/mysql/ mv old_db_name new_db_name service mysql start # Ctrl+D to exit sudo # Reapply old DB's privileges to new DB
DDL¶
Remove duplicated table name prefix¶
- Replace regexp
(?:\b|(?<=_))(\w+)_\1
with$1
Reset constraint name¶
- Replace regexp
(?<=\bCONSTRAINT `fk_)\w+-[\w-]+(?=` FOREIGN KEY \(`(\w+)` \))
with$1_[table]1