Rename or change name of MySQL table

Contributor Icon Contributed by qmchenry  
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.

 

26 Comments -


  1. subrahmanyam said on November 20, 2008

    It is very good.

  2. Senaia said on November 25, 2008

    Thanks, thats what I need :)

    Dont we all love google :D

  3. Stone Deft said on November 28, 2008

    Hey that was simple I thought it wouldn’t work but it did…

  4. ben said on December 13, 2008

    That did not work for me. Using MySQL 4.1.25.

  5. mosab said on December 17, 2008

    thank you

  6. hardik said on December 22, 2008

    thx a lot smarty

  7. xyz said on January 29, 2009

    vey nice i’m impressed by the precise answer
    keep it up
    i wish i could get answers this way….
    :-)

  8. MADP said on February 15, 2009

    Giant of yours! thanks for the tip.

  9. anonymouse said on April 15, 2009

    Thanks! Very straight to the point.

  10. fabio said on April 20, 2009

    beautiful – thnx

  11. Rik said on May 31, 2009

    Great Thx, simple but effective!

  12. Anonymous said on October 12, 2009

    Very Impressive

  13. hbunny said on November 26, 2009

    thank you for this post, really helpful, and yes Senaia, thank God there’s google :)

  14. sasimkumar said on December 28, 2009

    Thanks for the syntax and it is very useful for my learning …

  15. Anonymous said on January 8, 2010

    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?

  16. Патрик Жданов said on February 4, 2010

    Thanks! it worked!
    Gracias! Funcionó!

  17. Vivekv2v said on June 16, 2010

    good i got correct result form hire……..

  18. Ssss said on August 29, 2010

    tum chutiya ho saale naya version use krne me ho rha hai tume pyar ho gaya hai 4.1 se..

  19. Inyourface said on November 4, 2010

    what was the necessity to use inappropriate language?!

  20. Topik1 said on January 1, 2011

    so nice

  21. Guest said on January 26, 2011

    Thanks a lot…i was desperately searching for it..

  22. Gaurav Havefunmedia said on February 7, 2011

    Thanks for the one line solution…

  23. abc said on March 31, 2011

    not impressive because i want inside mysql……….not through code

  24. Abc said on April 25, 2011

    Really man without the clutter got the butter

  25. parwinder said on April 28, 2011

    hw change the table name in mysql

    plz plz plz plz plz plz help me yr

  26. Nagaraj said on January 23, 2012

    Thanx its very use full….. :)

 

RSS feed for comments on this post. TrackBack URL

Leave a comment -