mysql資料不完整遷移指令碼

來源:互聯網
上載者:User

標籤:mysql bash

公司新平台上線,老資料庫中有一些原本的使用者資料需要遷移到新平台,特地開發這個指令碼,以保證資料的完整性,以及效率性#!/bin/bash##到出舊資料庫中需要的表echo "請在指令碼語言目錄下準備3個檔案,一個為tables.txt,裡面列出需要從舊資料庫中匯出的表名,另一個是oldmysqlauth舊資料庫的使用者帳號密碼以及資料庫,第三個是newmysqlauth新資料庫的使用者帳號密碼以及資料庫,分別列出格式為:        1        2        3 ..."counts=`awk ‘BEGIN{t=0;} { t++; }  END{print t; }‘ tables.txt`i=1mkdir sql if [ -e tables.txt  ] && [ -e oldmysqlauth ] && [ -e newmysqlauth ];then    while [ $i -le $counts ];    do       table=`awk -v awk_i="$i" ‘NR==awk_i{print}‘ tables.txt`;       /usr/bin/mysqldump -u`awk ‘NR==1{print}‘ oldmysqlauth` -p`awk ‘NR==2{print}‘ oldmysqlauth`  `awk ‘NR==3{print}‘ oldmysqlauth` $table  > sql/$table.sql            i=$((i+1))       done       else               echo "程式需要檔案不完整,請檢查"fiecho "已經將您需要的表從舊的資料庫中匯出,即將進行資料表還原"           ##將舊資料庫中匯出的表匯入新資料庫中k=1if [ -e tables.txt  ] && [ -e oldmysqlauth ] && [ -e newmysqlauth ];thenwhile [ $k -le $counts ]; do    table=`awk -v awk_k="$k" ‘NR==awk_k{print}‘ tables.txt`;        /usr/bin/mysql -u`awk ‘NR==1{print}‘ newmysqlauth` -p`awk ‘NR==2{print}‘ newmysqlauth`  `awk ‘NR==3{print}‘ newmysqlauth`  < /root/datapopulate/sql/$table.sql         k=$((k+1))    done    else        echo "程式需要檔案不完整,請檢查"fiecho "已經將舊資料庫中的表遷移到新的資料庫中,謝謝使用!"

本文出自 “技術宅私人空間” 部落格,請務必保留此出處http://chulinx.blog.51cto.com/4098114/1825337

mysql資料不完整遷移指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.