Rename or change name of MySQL table

Contributor Icon Contributed by qmchenry Date Icon July 4, 2006  
Tag Icon Tagged: MySQL

If you change your mind and want to rename an existing MySQL table, with or without data in it, it is no problem. One simple command will change the table’s name.


To change the name of an existing table first to second, use this command as a user with adequate privileges:

RENAME TABLE first TO second;

It is good DBA manners to make sure that no one and no program are using this table before making the name change.

Previous recipe | Next recipe |
 
  • subrahmanyam
    It is very good.
  • Thanks, thats what I need :)

    Dont we all love google :D
  • Hey that was simple I thought it wouldn't work but it did...
  • ben
    That did not work for me. Using MySQL 4.1.25.
  • thank you
  • hardik
    thx a lot smarty
  • xyz
    vey nice i'm impressed by the precise answer
    keep it up
    i wish i could get answers this way....
    :-)
  • Giant of yours! thanks for the tip.
  • anonymouse
    Thanks! Very straight to the point.
  • fabio
    beautiful - thnx
  • Rik
    Great Thx, simple but effective!
  • azra_ayu
    Very Impressive
  • thank you for this post, really helpful, and yes Senaia, thank God there's google :)
  • Thanks for the syntax and it is very useful for my learning ...
  • danawaring
    Thanks for the advice to "make sure that no one and no program are using this table before making the name change." Are there commands to do this? Could it possibly have been a joke, implying that we should telephone hundreds of users, email dozens of developers, make a list of who is logged on to what (which security people frown on doing), restrict logins for a week, and stop all processes? Doesn't the atomic nature of the rename mean that it is safe to update a second table, rename the first table to backup and the new table to the first table atomically?
  • Патрик Жданов
    Thanks! it worked!
    Gracias! Funcionó!
blog comments powered by Disqus