How to remove a prefix name from every table name in a mysql database

后端 未结 3 2029
醉酒成梦
醉酒成梦 2021-01-13 01:30

I have a joomla mysql database with a table name prefix of \"jos_\" on all of my table names. But I would like to remove it from all of my tables. I understand how to rename

3条回答
  •  粉色の甜心
    2021-01-13 02:35

    You can generate the necessary statements with a single query:

    select 'RENAME TABLE ' || table_name ||  ' TO ' || substr(table_name, 5) ||';'
    from information_schema.tables
    

    Save the output of that query to a file and you have all the statements you need.

    Or if that returns 0s and 1s rather the statemenets, here's the version using concat instead:

    select concat('RENAME TABLE ', concat(table_name, concat(' TO ', concat(substr(table_name, 5), ';'))))
    from information_schema.tables;
    

提交回复
热议问题