MySQL Data incomplete migration script

Source: Internet
Author: User

Company new platform on-line, the old database has some original user data need to migrate to the new platform, specially developed this script to ensure data integrity, and efficiency #!/bin/bash# #到出旧数据库中需要的表echo   "Please prepare 3 files in the scripting language directory, One for Tables.txt, which lists the name of the table that needs to be exported from the old database, the user account password Oldmysqlauth the old database, and the database, and the third is the user account password and database for the Newmysqlauth new database, listed in the form:         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  "program requires incomplete files, please check" fiecho  "You have exported the tables you need from the old database and are about to restore the data table"            ## Import the exported tables from the old database into the new database 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 ' &NBsp;-p ' awk  ' nr==2{print} '  newmysqlauth '    ' awk  ' nr==3{print} '  newmysqlauth '    < /root/datapopulate/sql/$table. sql         k=$ ((k + 1))     done    else         echo  "program requires incomplete files, please check" fiecho  "has migrated the old database tables to the new database, thank you for using! "

This article is from the "Technology House private Space" blog, please be sure to keep this source http://chulinx.blog.51cto.com/4098114/1825337

MySQL Data incomplete migration script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.