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