【Mysql】改数据库库名操作

发布时间:2020-08-15 14:59:02 作者:小亮520cl
来源:ITPUB博客 阅读:132

MySQL在5.1引入了一个rename database操作,但在MySQL5.1.23后又不支持这个命令。可以说是一个实验性的功能,没有在生产中支持过(mysql-5.1 release在mysql-5.1.30),那么生产中我们有时为了追求完美需要改一下库名。怎么操作呢?
这里提供一个变通的方法。
1. 创建出新库名:

此处)折叠或打开
  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  执行即可

点击(此处)折叠或打开

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





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

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》