• ADADADADAD

    【Mysql】改数据库库名操作[ mysql数据库 ]

    mysql数据库 时间:2024-12-03 12:11:42

    作者:文/会员上传

    简介:

    MySQL在5.1引入了一个rename database操作,但在MySQL5.1.23后又不支持这个命令。可以说是一个实验性的功能,没有在生产中支持过(mysql-5.1 release在mysql-5.1.30),那么生产中我

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

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

    点击(此处)折叠或打开

      mysql> source /tmp/rename_to_db_v2.sql;





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

    【Mysql】改数据库库名操作.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载
    热门标签: mysql数据库库名