在phpMyAdmin中删除数据库中所有表的公共前缀
Delete common prefix of all tables in DB in phpMyAdmin
我所有的 table 都有前缀 bn_
。例如,table 将被命名为 bn_blast
.
对 运行 的任何 SQL 命令都会删除所有 table 中的所有前缀?
单线
在控制台中:
mysql -u root -p -AN -e" select concat('RENAME TABLE ', concat(table_name, concat(' TO ', concat(substr(table_name,4 ), ';')))) from information_schema.tables where table_schema='db_name' " > renaming.sql
出现提示时输入密码。
打开"renaming.sql"文件,在第一行添加"use db_name;",然后保存。
然后,执行以下操作:
mysql -u root -p < renaming.sql
出现提示时输入密码。
现在,检查您的表格:
show tables;
输出:之前
mysql> show tables;
+---------------------+
| Tables_in_STACK |
+---------------------+
| db_answer |
| db_answers |
| db_circle |
| db_fee |
| db_housing |
| db_im_originals |
| db_im_savegroups |
| db_im_savespecs |
| db_location_share |
| db_order1 |
| db_orderitems |
| db_patientinfo |
| db_quest |
| db_share |
| db_t2 |
| db_tbdatabaseerrors |
| db_tblchanges |
| db_test |
| db_test1 |
| db_test_fid |
| db_test_table |
| db_testing |
| db_user |
+---------------------+
输出:
之后
mysql> show tables;
+-------------------+
| Tables_in_STACK |
+-------------------+
| answer |
| answers |
| circle |
| fee |
| housing |
| im_originals |
| im_savegroups |
| im_savespecs |
| location_share |
| order1 |
| orderitems |
| patientinfo |
| quest |
| share |
| t2 |
| tbdatabaseerrors |
| tblchanges |
| test |
| test1 |
| test_fid |
| test_table |
| testing |
| user |
+-------------------+
要使用 phpMyAdmin 删除 MySQL 数据库中所有 table 的公共前缀:
Select数据库。
转到“结构”选项卡。
滚动到底部,然后单击“全部选中”复选框。这 select 都是 table。
在“With selected:”旁边的下拉菜单中,select“替换table前缀”。这会将您带到 "Replace table prefix" 页面。
在“From”字段中,输入要删除的前缀,例如 shop_
.
在“至”字段中,将其留空。
单击“提交”...然后砰!完成!
您可以用类似的方式添加或重命名前缀。
提示:如果您的数据库有很多其他 table,而您只想 select 包含特定字符串的 table,您可以使用调试 JavaScript控制台。例如,对于select所有包含shop_
的table,运行这个:
$('form[name=tablesForm]').find('th:contains(shop_)').closest('tr').children(':first-child')
.find(':input[type=checkbox]').prop('checked', true)
我所有的 table 都有前缀 bn_
。例如,table 将被命名为 bn_blast
.
对 运行 的任何 SQL 命令都会删除所有 table 中的所有前缀?
单线
在控制台中:
mysql -u root -p -AN -e" select concat('RENAME TABLE ', concat(table_name, concat(' TO ', concat(substr(table_name,4 ), ';')))) from information_schema.tables where table_schema='db_name' " > renaming.sql
出现提示时输入密码。
打开"renaming.sql"文件,在第一行添加"use db_name;",然后保存。 然后,执行以下操作:
mysql -u root -p < renaming.sql
出现提示时输入密码。
现在,检查您的表格:
show tables;
输出:之前
mysql> show tables;
+---------------------+
| Tables_in_STACK |
+---------------------+
| db_answer |
| db_answers |
| db_circle |
| db_fee |
| db_housing |
| db_im_originals |
| db_im_savegroups |
| db_im_savespecs |
| db_location_share |
| db_order1 |
| db_orderitems |
| db_patientinfo |
| db_quest |
| db_share |
| db_t2 |
| db_tbdatabaseerrors |
| db_tblchanges |
| db_test |
| db_test1 |
| db_test_fid |
| db_test_table |
| db_testing |
| db_user |
+---------------------+
输出:
之后mysql> show tables;
+-------------------+
| Tables_in_STACK |
+-------------------+
| answer |
| answers |
| circle |
| fee |
| housing |
| im_originals |
| im_savegroups |
| im_savespecs |
| location_share |
| order1 |
| orderitems |
| patientinfo |
| quest |
| share |
| t2 |
| tbdatabaseerrors |
| tblchanges |
| test |
| test1 |
| test_fid |
| test_table |
| testing |
| user |
+-------------------+
要使用 phpMyAdmin 删除 MySQL 数据库中所有 table 的公共前缀:
Select数据库。
转到“结构”选项卡。
滚动到底部,然后单击“全部选中”复选框。这 select 都是 table。
在“With selected:”旁边的下拉菜单中,select“替换table前缀”。这会将您带到 "Replace table prefix" 页面。
在“From”字段中,输入要删除的前缀,例如
shop_
.在“至”字段中,将其留空。
单击“提交”...然后砰!完成!
您可以用类似的方式添加或重命名前缀。
提示:如果您的数据库有很多其他 table,而您只想 select 包含特定字符串的 table,您可以使用调试 JavaScript控制台。例如,对于select所有包含shop_
的table,运行这个:
$('form[name=tablesForm]').find('th:contains(shop_)').closest('tr').children(':first-child')
.find(':input[type=checkbox]').prop('checked', true)