How to add prefix of all tables in mysql

前端 未结 4 1306
广开言路
广开言路 2021-01-31 11:32

How can I add prefix to all tables in mysql using query.

For example:

I need to add \"dr_\" in all tables which are available in mysql database.

4条回答
  •  礼貌的吻别
    2021-01-31 12:12

    Add a prefix to all of your database tables.

    Supposing that your database was called "my_database" and the prefix you want to add is "my_prefix", execute the following query:

    SELECT Concat('ALTER TABLE ', TABLE_NAME, ' RENAME TO my_prefix_', TABLE_NAME, ';') FROM information_schema.tables WHERE table_schema = 'my_database'
    

    Your result set will be a bunch of queries that you can copy and paste into your favorite MySQL editor (Sequel Pro, phpMyAdmin, whatever). Just paste those in and execute, and you're all done.

提交回复
热议问题