Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
8 views
in SQL by (2.6k points)
recategorized by
Could someone tell me how to quickly rename a SQL database and change the schema name?

1 Answer

0 votes
by (7.2k points)
edited by

To quickly rename a mysql database you need to  create the new empty database, then rename each table in turn into the new database:

RENAME TABLE old_db.table TO new_db.table;

After executing the above command then you will need to adjust the permissions after that.:

mysql -u username -ppassword old_db -sNe 

'show tables' | while read table; \ 

    do mysql -u username -ppassword -sNe "rename table old_db.$table to new_db.$table"; done

Intellipaat provides the Best Database Courses for its learners. Enroll now!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 6, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...