MySQL/Bulk rename tablename

Aus crazylinux.de
Zur Navigation springen Zur Suche springen

Sample:

DB = nagiostest

tablenames = nagios_foo

new tablename = npc_foo


select concat('rename table nagios_',table_name,' to npc_',table_name,';') as cmd  from (
select mid(table_name,8,length(table_name)-7) as table_name from information_schema.tables
where table_name like 'nagios_%' and `TABLE_SCHEMA` = 'nagiostest') as foo


Result:

rename nagios_acknowledgements to npc_acknowledgements;
rename nagios_commands to npc_commands;
rename nagios_commenthistory to npc_commenthistory;
rename nagios_comments to npc_comments;
rename nagios_configfiles to npc_configfiles;

now run this commands in your sql-window