I have a MySQL database with several tables and I'm migrating to another database.
I have a Client and must be a client PE
I have Product and must be Product_PE
How can I accomplish this without however pausing to rename each of the 50 tables?
I have a MySQL database with several tables and I'm migrating to another database.
I have a Client and must be a client PE
I have Product and must be Product_PE
How can I accomplish this without however pausing to rename each of the 50 tables?
The easiest way , since 50 is a not-so-large number of rows:
RENAME TABLE
Cliente TO Cliente_PE,
Produto TO Produto_PE,
TabelaX TO TabelaX_PE
See the SQL manual .
You can also do this using phpmyadmin
, but then you'll be adding a prefix to the tables (PE_Client, etc):
Check All
checkbox. Add prefix to table
. prefix_
, in your case, PE_
.
To rename a table, you use the
RENAME TABLE nomeOriginal TO nomeNovo
Since there are many tables, you can use this query to automatically generate all% s of% s:
SELECT
CONCAT(
'RENAME TABLE '', table_schema, ''.'', table_name,
'' TO '', table_schema, ''.'', table_name, '_PE';' )
FROM
INFORMATION_SCHEMA.TABLES WHERE table_schema="NomeDoDb";
Output example:
RENAME TABLE 'NomeDoDb'.'eventos' TO 'NomeDoDb'.'eventos_PE';
RENAME TABLE 'NomeDoDb'.'fotos' TO 'NomeDoDb'.'fotos_PE';
RENAME TABLE 'NomeDoDb'.'usuarios' TO 'NomeDoDb'.'usuarios_PE';
Then just take the result and execute as a new query, either via copy & paste , redirecting to a SQL script, etc.
Advantages:
RENAME
or manually; WHERE
clause; WHERE
, and use it whenever you need, eg PROCEDURE
In phpmyadmin (or adminer), go to "SQL" and type the command:
RENAME TABLE current_name TO new_name
Click Run. After that, give F4 to update the list of bank tables!