Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename a table in MySQL

Renaming a table is not working in MySQL

RENAME TABLE group TO member; 

The error message is

#1064 - You have an error in your SQL syntax; check the manual that corresponds         to your MySQL server version for the right syntax to use near 'group          RENAME TO member' at line 1 

The query is working fine on other tables for me, but not with the table group.

like image 441
Anil Olakkal Avatar asked Sep 29 '12 06:09

Anil Olakkal


People also ask

Can we rename database in MySQL?

Rename MySQL Database from Command Line Log into the server, and open a command line / terminal window. (If you're working remotely, connect to the server via SSH.) Replace [UserName] and [Password] with the actual credentials for the database, and replace [DB_Name] with the exact name of the database you're changing.

Can we rename the table name?

Any database user can easily change the name by using the RENAME TABLE and ALTER TABLE statement in Structured Query Language. The RENAME TABLE and ALTER TABLE syntax help in changing the name of the table.


1 Answers

group is a keyword (part of GROUP BY) in MySQL, you need to surround it with backticks to show MySQL that you want it interpreted as a table name:

RENAME TABLE `group` TO `member`; 

added(see comments)- Those are not single quotes.

like image 79
Joachim Isaksson Avatar answered Sep 17 '22 16:09

Joachim Isaksson