Project

General

Profile

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

  1. Replace regexp
    (?:\b|(?<=_))(\w+)_\1
    
    with
    $1

Reset constraint name

  1. Replace regexp
    (?<=\bCONSTRAINT `fk_)\w+-[\w-]+(?=`
        FOREIGN KEY \(`(\w+)` \))
    
    with
    $1_[table]1