Help Center/ GaussDB(for MySQL)/ Troubleshooting/ Basic Issues/ Renaming Databases and Tables
Updated on 2023-10-19 GMT+08:00

Renaming Databases and Tables

GaussDB(for MySQL) uses the MySQL Community Edition to rename databases and tables.

  • Renaming table names: Run the rename table a to b; statement. You can rename a table to move a table from one database to another. For example, rename table da.ta to db.ta moves the table ta from the database da to the database db.
  • Renaming database names: Use the rename table command to move all tables from the original database to a new database, and then delete the original database. Example:
    # Access the original database.
    use ta;
    # Show all table names in the original database.
    Show tables;
    # View the CREATE DATABASE statement in the original database.
    Show create database ta;
    # Use the CREATE DATABASE statement in the original database to create a new database. (Change only the database name.)
    create database tb;
    # Move all tables from the original database to the new database.
    rename table da.ta to db.ta;
    rename table da.tb to db.tb;
    rename table da.tc to db.tc;
    ...
    # Delete the original database.
    Drop database ta;