Hello, friends. In this post, you will learn how to rename a table in MySQL / MariaDB, The procedure is simple and can save you some headache.
In some situations, you may want to rename a certain table in MySQL / MariaDB. This process although simple is important to know if you work daily with this powerful database manager.
Install MySQL / MariaDB
The procedure to install MySQL / MariaDB will depend on your distribution. However, we have several posts that talk about it, so just follow it for your system.
- How to install MariaDB on Ubuntu 22.04
- How to install MariaDB on Fedora 36
- How to install MariaDB on Rocky Linux 9 / CentOS 9 Stream
Once you have MySQL / MariaDB ready for work, you can continue.
How to rename a table in MySQL / MariaDB
Once you are connected to the program console, you can follow this structure
RENAME TABLE `DATABASE`.`TABLE NAME` TO `DATABASE`.`NEW TABLE NAME`;
As you can see, the structure of the command is simple to follow. In short, just specify with
RENAME the current table name and a new one.
Pressing ENTER will make the change.
Another option, just as easy but more explicit, consists in choosing and using the database where the table to rename is located
And from there, execute this command
RENAME TABLE `TABLE NAME` TO `NEW TABLE NAME`;
For this post, I will create a database called
Sample and inside it a table
Car with some structure
CREATE DATABASE Sample; use Sample; CREATE TABLE `Car` (id INT(11) default NULL auto_increment, s char(60) default NULL, PRIMARY KEY (id) );
Now, let’s rename it
RENAME TABLE `Sample`.`Car` TO `Sample`.`Kar`;
Now show the changes
In this post, you learned how to rename tables in MySQL / MariaBD. So quick and easy, a trick that can help you.