RENAME {DATABASE | SCHEMA}db_name
TOnew_db_name
;
This statement was added in MySQL 5.1.7 but was found to be
dangerous and was removed in MySQL 5.1.23. It was intended to
enable upgrading pre-5.1 databases to use the encoding implemented
in 5.1 for mapping database names to database directory names (see
Section 8.2.3, “Mapping of Identifiers to File Names”). However, use of this
statement could result in loss of database contents, which is why
it was removed. Do not use RENAME DATABASE
in
earlier versions in which it is present.
To perform the task of upgrading database names with the new
encoding, use ALTER DATABASE
instead (see Section 12.1.1, “db_name
UPGRADE DATA DIRECTORY
NAMEALTER DATABASE
Syntax”).
User Comments
You can change the database, table by table, using RENAME TABLE:
CREATE DATABASE new_db_name;
for each table: RENAME TABLE old_db_name.table_name TO new_db_name.table_name;
For some reasons table with triggers gave me a error and rename didn't work. I was forced to drop the triggers and after to recreate them in the new database.
I did SHOW TRIGGERS; to get all the triggers name after I did SHOW CREATE TRIGGER name; for every trigger, copied the results to a file, after I did DROP TRIGGER name; and finally I did RENAME TABLE .. (like in the beginning) After the table is in the new database, you can create the triggers.
Hope this helped some one.
Cheers from Moldova.
You don't have to do it on a table basis. Just use mysqldump to a file without the create-db option (msyqldump --routines xyz > dump.sql). Then create your new database and source that dump.
Add your own comment.