What are the best practices for renaming a database in TiDB?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: TIDB 修改数据库名有什么好方案

| username: 奋斗的大象

It cannot support the following statement like MySQL:
RENAME DATABASE esss_db.test_ins TO esss_test_db.test_ins

| username: TiDB_C罗 | Original post link

You made a mistake, it should be rename table.

| username: 奋斗的大象 | Original post link

Yes, RENAME table esss_db.test_ins TO esss_test_db.test_ins will do.

| username: Soysauce520 | Original post link

Batch rename table is not supported.

| username: Miracle | Original post link

What is your scenario?
If renaming the database is not supported, see if there is an alternative solution.

| username: zhanggame1 | Original post link

There’s no good solution, just export and then import.

| username: Kongdom | Original post link

Usually, it’s either renaming the table or exporting and importing.

| username: 路在何chu | Original post link

This is not supported. You can only export all tables and then import them.

| username: 哈喽沃德 | Original post link

Why do you want to change the database name?

| username: residentevil | Original post link

MySQL does not have a direct RENAME database operation; it needs to be resolved through data migration.

| username: redgame | Original post link

There is no good solution, just export it.

| username: TiDBer_aaO4sU46 | Original post link

Can’t be changed, rebuild, import.

| username: 啦啦啦啦啦 | Original post link

Just write a small script to batch rename tables, importing and exporting is too troublesome.

| username: TIDB-Learner | Original post link

Renaming databases is safe, but it has been deprecated. Has anyone done batch renaming of tables in a production database? Will there be any unexpected issues?

| username: residentevil | Original post link

Let’s start with read-only operations and avoid online writes for now.

| username: TiDBer_rvITcue9 | Original post link

Using third-party tools for batch import and export is convenient.

| username: kelvin | Original post link

I think it’s better to export and import.

| username: TiDBer_RjzUpGDL | Original post link

Create a new database, then import.

| username: 这里介绍不了我 | Original post link

For the production environment, it is recommended to use import and export, and write a script offline to batch rename tables.

| username: DBAER | Original post link

Write a script to batch rename tables.