Databases InterBase (28) MS-SQL (5) mysql (33) Oracle (1)
Exchange Links About this site Links to us
|
mysql: How can I rename a database
8 comments. Current rating: (4 votes). Leave comments and/ or rate it.
Question:
I want to rename my database from 'TEST' to something more meaningful. Do I have to make a backup, modify the SQL script and then restore it?
Answer:
While that would work, there is an easier way. Shutdown the mysql server, rename the directory that stores the database from 'TEST' to your desired name. This 'TEST' directory is below the data directory. If you don't know where that is, try:
$ mysqladmin variables | grep datadir
After renaming, restart the MySQL server and check the grants - they might still contain references to the old database name.
You can also use a tool like phpMyAdmin (web interface to mysql) which has an option to rename a database.
Comments:
|
|
|
|
|
|
|
|
|
Worked perfectly!
If you're renaming the DB by command line, you'll want to grant user permissions to the new DB and delete permissions granted for the old DB. At a minimum, you'll need to run the following SQL:
remove from mysql.db where db='oldDBname';
|
|
|
|
|
try this..
$ mysqladmin create new_db
$ mysqldump --opt old_db | mysql new_db
mysql>; revoke all from old_db_user@host;
|
|
|
|
|
MySQL 5.x added rename database
try rename table for Mysql 4.x
|
|
|
|
|
Actually, the rename statement is only available from version 5.1.7 (according to the MySQL documentation).
|
|
|
|
|
And, as I read in the MySQL docs, it was removed due to it's serurity-breach-iness. It seems as if there is no way to do this... Copying to a new DB seems reasonable, but I can't believe there's no RENAME DB COMMAND available...
|
|
|
|
|
I think that renaming the directory will cause trouble for those of you using stored procedures.
|
|
|
|
|
not being able to just rename a schema blows ass
|
|