Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 我想rename database 如何实现

I want to change the database name, how can I achieve this?
Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 我想rename database 如何实现
I want to change the database name, how can I achieve this?
create database new_db;
RENAME TABLE
command to change the table name and move the table to the new database:rename table old_db.tb to new_db.tb;
drop database old_db;
You can only recreate the database. If the business cannot be stopped, try using DM binlog synchronization.
In lower versions of MySQL, you can still rename the database, but in higher versions, you can’t. I guess TiDB doesn’t support it either, so it’s better to use the rename db.table syntax.
For versions above v6.4, you can use flashback database to change the database name.
FLASHBACK DATABASE | PingCAP Documentation Center
DROP DATABASE test;
FLASHBACK DATABASE test TO test1;
It’s pretty good, but will there be any exceptions that can’t be recovered from…
Haha, this idea is very bold and also very risky.
Under normal circumstances, it is indeed feasible, but under abnormal circumstances, you might need to run away
I think it’s more reliable to dump it out and then import it again, at least there will be backup data.
Yes, I agree with your statement, it is stable and reliable.