简体   繁体   中英

Rename part of all table names in MySQL

I'm currently looking for a way, to rename all tables in my db. But I don't want to rename to whole table name (you can find a lot of question about renaming whole table names on SO). So in my case I've a prefix calles wp_ before each table name what I'll replace with tnd_ .

So is there a smart way how I can do this? Because I've about 200+ tables and I don't want to change every table name by hand.

Thanks for your help!

I think it would work:

SELECT Concat('ALTER TABLE `', TABLE_NAME, '` RENAME TO `dr_', TABLE_NAME, '`;') 
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '<name of your db>';

Reference: How to add prefix of all tables in mysql

If you use PHP admin, you can also check: Rename and add prefix to all tables with phpMyAdmin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM