安全快速更改MySQL資料庫名稱

來源:互聯網
上載者:User

安全快速更改MySQL資料庫名稱
導讀MySQL似乎沒有更改資料庫名稱的語句(也許是我不知道),如果你有資料庫伺服器的系統管理權限,可以直接更改一下目錄名即可,但如果沒有許可權,可以通過更改表名達到修改資料庫名的目的。下面是把centos資料庫更改為centos_old。1、建立資料庫centos_old.

mysql > create database centos_old;
2、使用select concat拼成所有rename table的語句。
    mysql -uroot -p -e "select concat('rename table centos.',table_name,' to centos_old.',table_name,';') from information_schema.TABLES where TABLE_SCHEMA='centos';" > rename_mysql_name.sql

開啟rename_mysql_name.sql,把第一行刪除。

rename_mysql_name.sql內容大概為:

    rename table centos.wp_commentmeta to centos_old.wp_commentmeta;    rename table centos.wp_comments to centos_old.wp_comments;    rename table centos.wp_forum_forums to centos_old.wp_forum_forums;    rename table centos.wp_forum_groups to centos_old.wp_forum_groups;    rename table centos.wp_forum_posts to centos_old.wp_forum_posts;    rename table centos.wp_forum_threads to centos_old.wp_forum_threads;    rename table centos.wp_forum_usergroup2user to centos_old.wp_forum_usergroup2user;    rename table centos.wp_forum_usergroups to centos_old.wp_forum_usergroups;    rename table centos.wp_links to centos_old.wp_links;    rename table centos.wp_options to centos_old.wp_options;    rename table centos.wp_postmeta to centos_old.wp_postmeta;    rename table centos.wp_posts to centos_old.wp_posts;    rename table centos.wp_term_relationships to centos_old.wp_term_relationships;    rename table centos.wp_term_taxonomy to centos_old.wp_term_taxonomy;    rename table centos.wp_terms to centos_old.wp_terms;    rename table centos.wp_usermeta to centos_old.wp_usermeta;    rename table centos.wp_users to centos_old.wp_users;
3、執行rename語句
mysql -uroot -p < rename_mysql_name.sql

這樣就完成了centos資料庫名更改為centos_old的操作。

原文地址:https://www.centos.bz/2013/09/quick-and-secure-modify-mysql-name/

本文地址:http://www.linuxprobe.com/linux-mysql.html


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.