sqlite迁移到mysql脚本的方法
废话不多说了,直接给大家贴代码了,具体代码如下所示:
#!/usr/bin/perl # #basedonhttps://stackoverflow.com/a/87531/5742651 #usage:sqlite3.dumpdatabase_name.sqlite3|perlsqlite2mysql.pl|mysql-uroot-p$import_database_name # #ignorefollowlines: #BEGINTRANSACTION #COMMIT #sqlite_sequence #CREATEUNIQUEINDEX #PRAGMAforeign_keys=OFF #"tablename/field"=>`tablename/field` #booleans't'and'f'=>1and0 #AUTOINCREMENT=>AUTO_INCREMENT #varchar=>varchar(255) #CREATETABLEtable...=>DROPTABLEtable;CREATETABLEtable... #Mergeinsertsqlsintomultipleinserttospeedup #INSERTINTOtableVALUES('val1'); #INSERTINTOtableVALUES('val2');=>INSERTINTOtableVALUES('val1'),('val2'),('val3'); #INSERTINTOtableVALUES('val3'); my$open=0; my$line_cache=''; #Forspeedup print"SETGLOBALmax_allowed_packet=209715200;\n"; #print"SETAUTOCOMMIT=0;\n"; while($line=<>){ if(($line!~/PRAGMAforeign_keys=OFF/)&&($line!~/BEGINTRANSACTION/)&&($line!~/COMMIT/)&&($line!~/sqlite_sequence/)&&($line!~/CREATEUNIQUEINDEX/)){ if($line=~/CREATETABLE\"([a-z_0-9]*)\"(.*)/){ $name="\`$1\`"; $sub=$2; $sub=~s/varchar([^(])/varchar(255)$1/g; $line="DROPTABLEIFEXISTS$name;\nCREATETABLE$name$sub\n"; } elsif($line=~/CREATEVIEW([a-z_0-9]*)(.*)/){ $name="\`$1\`"; $sub=$2; $line="DROPVIEWIFEXISTS$name;\nCREATEVIEW$name$sub\n"; } elsif($line=~/INSERTINTO\"([a-z_]*)\"VALUES(.*);/){ if($open==0){ $open=1; $line_cache.="INSERTINTO\`$1\`VALUES$2"; }else{ $line_cache.=",$2"; } next; }else{ $line=~s/\'\'/\\\'/g; } if($open==1){ $open=0; $line=$line_cache.";\n".$line; $line_cache=''; } $line=~s/\"/`/g; $line=~s/([^\\'])\'t\'(.)/$1THIS_IS_TRUE$2/g; $line=~s/THIS_IS_TRUE/1/g; $line=~s/([^\\'])\'f\'(.)/$1THIS_IS_FALSE$2/g; $line=~s/THIS_IS_FALSE/0/g; $line=~s/AUTOINCREMENT/AUTO_INCREMENT/g; print$line; } } #print"SETAUTOCOMMIT=1;\n";
总结
以上所述是小编给大家介绍的sqlite迁移到mysql脚本的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!