phpMyAdmin批量修改MySQL資料表首碼的方法

來源:互聯網
上載者:User

phpMyAdmin批量修改MySQL資料表首碼的方法

多個網站共用一個改MySQL資料庫時,為使資料庫管理不混亂,一般採用不同的網站使用不同首碼名的方式進行區分。而如何批量修改已有資料庫的首碼名 呢?全部匯出修改後再匯入?還是一個表一個表的修改?今天我要介紹的是相對簡單的批量修改資料庫中表首碼的方法,適用於修改資料庫中相同首碼且資料表較多 的情況。

此例中假定修改名為“www_bkjia_com”的資料庫中首碼為“phpcms_”的表,並將所有符合條件表的首碼修改為“bkjia_”。

1.        用phpMyAdmin開啟要修改首碼的資料庫www_bkjia_com,執行以下SQL語句(其中加粗斜體字是需要根據實際需求替換的):

Select CONCAT( 'ALTER TABLE ', table_name, ' RENAME TO ', replace(table_name,'phpcms_','bkjia_'),';')

from information_schema.tables

where TABLE_SCHEMA = 'www_bkjia_com' and table_name LIKE 'phpcms_%';

2.    在執行SQL語句產生的頁面上點擊“匯出”,選擇“自訂”->“直接顯示為文本”,匯出txt格式就可以了

3.    執行匯出功能後,到達結果視窗如下,複製文字框中的內容 -------  這裡由於版本不同或許需要先處理一下

4.    執行txt裡的alert語句

匯出的alert語句類似於

ALTER TABLE v9_admin RENAME TO yanglao_admin;

LAMP架構協同應用的執行個體——phpMyAdmin

LAMP應用之phpMyAdmin、Wordpress

phpMyAdmin老出現登陸逾時解決方案

Ubuntu 安裝phpMyAdmin與Adminer

在LAMP基礎上實現SSL功能並安裝phpMyAdmin

Ubuntu 14.04 配置 LAMP+phpMyAdmin PHP(5.5.9)開發環境

phpMyAdmin 的詳細介紹:請點這裡
phpMyAdmin 的:請點這裡

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.