我有几个中小型的mysql数据库,大约40个,我需要将它们从一个具有不同cpanel帐户的whm服务器迁移到另一个具有从之前的服务器设置的帐户和我正在移动的数据库的旧版本地点。
任何人都可以推荐这样做的最快捷的方法,我要手动转储每一个并导入它,但它似乎非常耗时,我想尽可能切断我的机器作为中间人,我可以自动化。
我对cPanel知之甚less,但是我知道如何快速地将数据库传输到另一台服务器 – 如果你有权访问ssh。
用正确的参数使用mysqldump并用ssh链接它。 所以数据库在Sorce数据库仍然导出的同时被导入。 没有使用临时文件(内部除了mysql);)
sourceserver#mysqldump –user = user1 –all-databases | ssh targethost'mysql –user = user2'
如果使用私钥和ssh-agent向源服务器进行身份validation,则可以使用ssh的-A选项进行连接。 所以你不需要关心目标端的授权。 但请记住:
Agent forwarding should be enabled with caution. Users with the ability to bypass file permissions on the remote host (for the agent's Unix-domain socket) can access the local agent through the forwarded connection. An attacker cannot obtain key material from the agent, however they can perform operations on the keys that enable them to authenticate using the identities loaded into the agent.
(来源:man 1 ssh)
希望这个对你有帮助
可能有点过于@krissi的答案很好,但万一你不止一次,你可以使用这样的脚本:
#!/bin/bash # MySQL databases migration script # Jorge Barnaby (jorge {dot} barnaby {at} gmail) ################################################################################ # Configuration variables ORIG_USER="origin-username" ORIG_PASS="origin-password" ORIG_HOST="origin-server" DEST_USER="destination-username" DEST_PASS="destination-password" DEST_HOST="destination-server" # Do not backup the following databases IGNORED_DBS="information_schema" ################################################################################ # Start of the program # Command that runs on the origin server to extract the databases MYSQL_ORIG="mysqldump -u $ORIG_USER -h $ORIG_HOST -p$ORIG_PASS --add-drop-database --databases" # Command that runs on the destination server to popuplate the databases MYSQL_DEST="mysql -u $DEST_USER -h $DEST_HOST -p$DEST_PASS" # Get all database list first DBS="$(mysql -u $ORIG_USER -h $ORIG_HOST -p$ORIG_PASS -Bse 'show databases')" echo echo ----------------------------------------------------------- echo `date +"%F %T %Z"` : Starting MySQL Migration script echo ----------------------------------------------------------- echo echo -- MySQL Origin Server: $ORIG_HOST echo -- MySQL Destination Server: $DEST_HOST for db in $DBS do skipdb=-1 if [ "$IGNORED_DBS" != "" ]; then for i in $IGNORED_DBS do [ "$db" == "$i" ] && skipdb=1 || : done fi if [ "$skipdb" == "-1" ]; then echo echo -- `date +"%F %T %Z"` : Migrating database $db # Command to be executed piping mysqldump on the origin and mysql on the remote $MYSQL_ORIG $db | $MYSQL_DEST echo -- `date +"%F %T %Z"` : Done fi done echo echo ----------------------------------------------------------- echo `date +"%F %T %Z"` : All Done echo ----------------------------------------------------------- exit 0