【Mysql】改數(shù)據(jù)庫庫名操作

MySQL在5.1引入了一個(gè)rename database操作,但在MySQL5.1.23后又不支持這個(gè)命令。可以說是一個(gè)實(shí)驗(yàn)性的功能,沒有在生產(chǎn)中支持過(mysql-5.1 release在mysql-5.1.30),那么生產(chǎn)中我們有時(shí)為了追求完美需要改一下庫名。怎么操作呢?
這里提供一個(gè)變通的方法。
1. 創(chuàng)建出新庫名:

此處)折疊或打開
  1. mysql> select concat("rename table ",table_schema,".",table_name," to testbak.",table_name,";") into outfile '/tmp/rename_to_db_v2.sql' from information_schema.tables where table_schema='test';

[root@host-192-168-1-56 ~]# more /tmp/rename_to_db_v2.sql   
rename table test.bc_dbfsxiang to testbak.bc_dbfsxiang;
rename table test.bc_dkfsxiang to testbak.bc_dkfsxiang;
rename table test.bc_dkytxiang to testbak.bc_dkytxiang;
rename table test.bc_gzffxiang to testbak.bc_gzffxiang;
rename table test.bc_option_map to testbak.bc_option_map;
rename table test.bc_qylxxiang to testbak.bc_qylxxiang;
rename table test.bc_service_city to testbak.bc_service_city;
rename table test.bc_service_qi_city to testbak.bc_service_qi_city;
rename table test.bc_wffkhyxiang to testbak.bc_wffkhyxiang;
rename table test.bc_wffkzyxiang to testbak.bc_wffkzyxiang;
rename table test.bc_xindai to testbak.bc_xindai;
rename table test.bc_xindai_fields_v to testbak.bc_xindai_fields_v;
rename table test.bc_xindai_geren to testbak.bc_xindai_geren;
rename table test.bc_xindai_qiye to testbak.bc_xindai_qiye;
rename table test.bc_xyjlxiang to testbak.bc_xyjlxiang;
rename table test.bc_zyyqxiang to testbak.bc_zyyqxiang;
rename table test.fake_names to testbak.fake_names;
rename table test.idmap to testbak.idmap;
rename table test.sbtest to testbak.sbtest;
rename table test.tbUser to testbak.tbUser;
rename table test.test to testbak.test;
rename table test.test2 to testbak.test2;


3  執(zhí)行即可

點(diǎn)擊(此處)折疊或打開

成都創(chuàng)新互聯(lián)2013年開創(chuàng)至今,先為河南等服務(wù)建站,河南等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為河南企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

  1. mysql> source /tmp/rename_to_db_v2.sql;





原文地址:http://wubx.net/tips-mysql-rename-database/

本文標(biāo)題:【Mysql】改數(shù)據(jù)庫庫名操作
網(wǎng)頁URL:http://bm7419.com/article20/psdjjo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、網(wǎng)站制作網(wǎng)站改版、建站公司網(wǎng)站建設(shè)網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)