MySQL: Quick renaming of database in command line
Published March 19, 2020 • 1 min read
For example, if you can't rename a database with a tool like TablePlus, you can do it by command line with the following statement
$ mysql -u dbUserName -p"dbUserPassword" oldDatabaseName -sNe 'show tables' | while read table; do mysql -u dbUserName -p"dbUserPassword" -sNe "RENAME TABLE oldDatabaseName.$table TO newDatabaseName.$table"; done
This loop renames all tables in the affected database immediately.
mysql