如何从特定MySQL数据库中的每个表名中删除前缀名
特定的如何从特定MySQL数据库中的每个表名中删除前缀名,mysql,database,alter-table,Mysql,Database,Alter Table,特定的MySQL数据库中的所有表,例如myu db,都以前缀开头,其长度为17字符。我想从所有表的名称中删除前缀。如何做到这一点?我在语句中添加了where table_schema='my_db',该语句用于获取用于重命名my_db数据库中所有表的语句,而不是重命名MySQL服务器实例中所有数据库的所有表: select concat('RENAME TABLE ', concat(table_name, concat(' TO ', concat(substr(table_name, 18)
MySQL
数据库中的所有表,例如myu db
,都以前缀开头,其长度为17
字符。我想从所有表的名称中删除前缀。如何做到这一点?我在语句中添加了where table_schema='my_db'
,该语句用于获取用于重命名my_db
数据库中所有表的语句,而不是重命名MySQL服务器实例中所有数据库的所有表:
select concat('RENAME TABLE ', concat(table_name, concat(' TO ', concat(substr(table_name, 18), ';')))) from information_schema.tables where table_schema = 'my_db';
请注意前缀的长度是
17
,我在substr
命令中使用了18
。我在语句中添加了where table_schema='my_db'
,该语句用于获取用于重命名my_db
数据库中所有表的语句,不要重命名MySQL服务器实例中所有数据库的所有表:
select concat('RENAME TABLE ', concat(table_name, concat(' TO ', concat(substr(table_name, 18), ';')))) from information_schema.tables where table_schema = 'my_db';
注意前缀的长度是
17
,我在substr
命令中使用了18
。改进了hasanghaforian的答案。。。
删除了额外的concat函数。。仍然产生相同的输出
select concat('RENAME TABLE ', table_name, ' TO ' , substr(table_name,18) , ' ; ' ) from information_schema.tables where table_schema = 'my_db';
改进了hasanghaforian的答案。。。 删除了额外的concat函数。。仍然产生相同的输出
select concat('RENAME TABLE ', table_name, ' TO ' , substr(table_name,18) , ' ; ' ) from information_schema.tables where table_schema = 'my_db';