[MDEV-22532] Rename Database Created: 2020-05-12  Updated: 2020-11-27

Status: Open
Project: MariaDB Server
Component/s: Backup, Server
Fix Version/s: None

Type: Task Priority: Major
Reporter: Nuno Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: None


 Description   

I cannot find this documented anywhere, possibly because it is not supported/possible.

How do I rename a database in MariaDB?

From my research, it appears that "RENAME DATABASE" was possible in MySQL for a few versions, but considered unsafe, so it was removed.
I see other "hacky" ways of doing it, which involves moving tables, re-create triggers/views, rename files, etc...

What is THE way to do it with MariaDB, or is there a well-tested tool that does it?

Note - I understand that "mysqldump" can do the job, but it is not practicable for large databases.

This might be related (but not duplicate) to MDEV-18329 and MDEV-18762.



 Comments   
Comment by Daniel Black [ 2020-11-12 ]

Your "hacky ways" shouldn't include 'renaming files' (that's under the "crazy ways"). The broad and loose connections between authentication, triggers, events, foreign keys, sequences, replication filters, added to the complexity of renaming databases so much it couldn't be made reliable with the available engineering effort.

What's your use case for waning a rename database?

Comment by Nuno [ 2020-11-12 ]

There are many reasons when one would like to rename a database.

Things like when restoring to a Test server, rename it to "mydatabase_Test".

Or, for example, when one is expanding the business, and wants to make their original database more meaningful, like from "main" to "mybusiness1", so that it distinguishes from other newer databases on the server.

Or, when someone is leaving "cPanel", which forced you to have the cPanel username as prefix, and now you want to remove it. E.g. "cpaneluser_MyBusiness" to just "MyBusiness".

These are just small examples. Renaming database should be a basic feature to have, anyway.

I used a Percona script to do the job when I created this ticket. It worked quite well.

https://www.percona.com/blog/2013/12/24/renaming-database-schema-mysql/

Comment by Daniel Black [ 2020-11-15 ]

I think a script submission that starts by disclosing its known limitations would be acceptable. Unlike the percona script, something that uses `GRANT/REVOKE` to move privs would be appreciated.

Comment by Sergei Golubchik [ 2020-11-19 ]

Yes, it was removed from MySQL because it had too many very hard to fix bugs

Generated at Thu Feb 08 09:15:26 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.