【Mysql】改資料庫庫名操作
MySQL在5.1引入了一個rename database操作,但在MySQL5.1.23後又不支援這個命令。可以說是一個實驗性的功能,沒有在生產中支援過(mysql-5.1 release在mysql-5.1.30),那麼生產中我們有時為了追求完美需要改一下庫名。怎麼操作呢?
這裡提供一個變通的方法。
1. 建立出新庫名:
點選(此處)摺疊或開啟
-
mysql> create database testbak;
2生成rename語句,從olddb裡遷移;
點選(此處)摺疊或開啟
-
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 執行即可
點選(此處)摺疊或開啟
-
mysql> source /tmp/rename_to_db_v2.sql;
原文地址:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2061136/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL 資料庫操作MySql資料庫
- Golang原生sql操作Mysql資料庫增刪改查GolangMySql資料庫
- Mysql資料庫操作命令MySql資料庫
- PHP操作MySQL資料庫PHPMySql資料庫
- MySQL資料庫常用操作MySql資料庫
- 【Java】操作mysql資料庫JavaMySql資料庫
- MySQL資料庫基本操作MySql資料庫
- shell 操作mysql資料庫MySql資料庫
- Oracle、mysql資料庫增、刪、改OracleMySql資料庫
- nid 改變資料庫名,DBID資料庫
- mysql資料庫基本操作(六)MySql資料庫
- mysql資料庫基本操作(三)MySql資料庫
- mysql資料庫基本操作(四)MySql資料庫
- mysql資料庫基本操作(五)MySql資料庫
- 02、MySQL—資料庫基本操作MySql資料庫
- python資料庫(mysql)操作Python資料庫MySql
- python 操作mysql資料庫PythonMySql資料庫
- Python Mysql 資料庫操作PythonMySql資料庫
- python操作mysql資料庫PythonMySql資料庫
- 使用OTL操作MySQL資料庫MySql資料庫
- 如何修改MySQL資料庫名稱MySql資料庫
- 資料庫操作增刪改查模糊查資料庫
- Mysql資料庫基礎操作命令MySql資料庫
- Python之 操作 MySQL 資料庫PythonMySql資料庫
- MySQL資料庫操作、儲存引擎MySql資料庫儲存引擎
- MySQL系列:資料庫基本操作(1)MySql資料庫
- MySQL資料庫常用操作和技巧MySql資料庫
- 資料庫名、例項名、資料庫域名、全域性資料庫名、服務名概念區分資料庫
- python資料庫-MySQL資料庫高階查詢操作(51)Python資料庫MySql
- 03-mysql資料庫怎刪改查MySql資料庫
- MySQL(一) 資料表資料庫的基本操作MySql資料庫
- YII1 增、刪、改、查資料庫操作資料庫
- MySQL顯示連線的資料庫名MySql資料庫
- SQLALchemy操作MySQL關係型資料庫MySql資料庫
- mysqlclient操作MySQL關係型資料庫MySqlclient資料庫
- Go語言中mysql資料庫操作(一)GoMySql資料庫
- 2.資料庫Mysql--------基本操作資料庫MySql
- 01-python操作Mysql資料庫PythonMySql資料庫