elliott.david 2008-08-25 08:47 采纳率: 25%
浏览 218

不使用 mysqldump 而复制 / 重复数据库

Without local access to the server, is there any way to duplicate/clone a MySQL db (with content and without content) into another without using mysqldump?

I am currently using MySQL 4.0.

转载于:https://stackoverflow.com/questions/25794/copy-duplicate-database-without-using-mysqldump

  • 写回答

7条回答

  • ℙℕℤℝ 2010-01-03 14:54
    关注

    If you are using Linux, you can use this bash script: (it perhaps needs some additional code cleaning but it works ... and it's much faster then mysqldump|mysql)

    #!/bin/bash
    
    DBUSER=user
    DBPASSWORD=pwd
    DBSNAME=sourceDb
    DBNAME=destinationDb
    DBSERVER=db.example.com
    
    fCreateTable=""
    fInsertData=""
    echo "Copying database ... (may take a while ...)"
    DBCONN="-h ${DBSERVER} -u ${DBUSER} --password=${DBPASSWORD}"
    echo "DROP DATABASE IF EXISTS ${DBNAME}" | mysql ${DBCONN}
    echo "CREATE DATABASE ${DBNAME}" | mysql ${DBCONN}
    for TABLE in `echo "SHOW TABLES" | mysql $DBCONN $DBSNAME | tail -n +2`; do
            createTable=`echo "SHOW CREATE TABLE ${TABLE}"|mysql -B -r $DBCONN $DBSNAME|tail -n +2|cut -f 2-`
            fCreateTable="${fCreateTable} ; ${createTable}"
            insertData="INSERT INTO ${DBNAME}.${TABLE} SELECT * FROM ${DBSNAME}.${TABLE}"
            fInsertData="${fInsertData} ; ${insertData}"
    done;
    echo "$fCreateTable ; $fInsertData" | mysql $DBCONN $DBNAME
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料