Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename and add prefix to all tables with phpMyAdmin

I want to add a prefix and rename all tables in a database with PhpMyAdmin.

I’ve tried these 2 scripts :

1)

select concat('rename table', table_name, ' to ', 'prefix_',table_name,';') from information_schema.tables where table_schema='db_name';

2)

SELECT Concat('ALTER TABLE ', TABLE_NAME, ' RENAME TO osc_', TABLE_NAME, ';') FROM INFORMATION_SCHEMA.TABLES where table_schema='db_name';

phpMyAdmin says the script is ok (see screen shot) but nothing change. What i am missing with phpMyAdmin ?

enter image description here

like image 486
Sébastien Gicquel Avatar asked Dec 03 '22 16:12

Sébastien Gicquel


1 Answers

Finally, i found an easy way to do that :

  1. select all tables you want to add a prefix

  2. choose in the select option : replace prefix table

  3. fill the field with the prefix (including the underscore) as in pfx_

Screenshot of phpMyAdmin :

phpMyAdmin select all tables and add table prefix

phpMyAdmin add table prefix

result : prefix is added to all tables selected

Note : In case your website is no more connected to your data base after this modification, you can restart your serveur, MAMP, etc

like image 154
Sébastien Gicquel Avatar answered Dec 11 '22 12:12

Sébastien Gicquel