When multiple websites share a mysql database,In order to make the database management not chaotic,Generally, different websites use different prefix names to distinguish them.And how to batch modify the prefix names of existing databases?Export all changes before importing?Or table-by-table modification?Today I want to introduce a relatively simple method to modify the table prefix in the database.It is suitable for modifying the same prefix in the database and many data tables.

This example assumes that the modification is named "www_sdck_cn"in the database with the prefix"phpcms_"table and modify the prefix of all qualifying tables to"sdck_".

1. Use phpmyadmin to open the database www_sdck_cn whose prefix i want to modify, and execute the following SQL statement (where bold italics need to be replaced according to actual needs):

select concat ("alter table", table_name, "rename to", replace (table_name, "phpcms_","sdck_"),";")

from information_schema.tables

where table_schema="www_sdck_cn"and table_name like"phpcms_%";

2. Click "Export" on the page generated by executing the SQL statement, select "Custom"->"Display directly as text", csv format, clear the "content separator" is empty

3. After executing the export function,The result window is as follows,Copy the contents of the text box

4. Enter the database "www_sdck_cn"SQL execution window,Paste the code into the sql text box,carried out. See if the relevant data sheet has been modified.


Data manipulation is risky,Please back up your data before proceeding.

  • Previous Labelauty–jQuery radio/checkbox landscaping plugin sharing
  • Next How to implement ASPNET GridView folding and stretching effect with jQuery