這篇文章主要介紹了sqlite如何遷移到MySQL腳本,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
站在用戶的角度思考問題,與客戶深入溝通,找到永濟(jì)網(wǎng)站設(shè)計與永濟(jì)網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都做網(wǎng)站、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名與空間、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋永濟(jì)地區(qū)。
,具體代碼如下所示:
#! /usr/bin/perl # # based on https://stackoverflow.com/a/87531/5742651 # usage: sqlite3 .dump database_name.sqlite3 | perl sqlite2mysql.pl | mysql -u root -p $import_database_name # # ignore follow lines: # BEGIN TRANSACTION # COMMIT # sqlite_sequence # CREATE UNIQUE INDEX # PRAGMA foreign_keys=OFF # "tablename/field" => `tablename/field` # booleans 't' and 'f' => 1 and 0 # AUTOINCREMENT => AUTO_INCREMENT # varchar => varchar(255) # CREATE TABLE table... => DROP TABLE table; CREATE TABLE table... # Merge insert sqls into multiple insert to speed up # INSERT INTO table VALUES('val1'); # INSERT INTO table VALUES('val2'); => INSERT INTO table VALUES('val1'), ('val2'), ('val3'); # INSERT INTO table VALUES('val3'); my $open=0; my $line_cache = ''; # For speed up print "SET GLOBAL max_allowed_packet=209715200;\n"; #print "SET AUTOCOMMIT=0;\n"; while ($line = <>){ if (($line !~ /PRAGMA foreign_keys=OFF/) && ($line !~ /BEGIN TRANSACTION/) && ($line !~ /COMMIT/) && ($line !~ /sqlite_sequence/) && ($line !~ /CREATE UNIQUE INDEX/)){ if ($line =~ /CREATE TABLE \"([a-z_0-9]*)\"(.*)/){ $name = "\`$1\`"; $sub = $2; $sub =~ s/varchar([^(])/varchar(255)$1/g; $line = "DROP TABLE IF EXISTS $name;\nCREATE TABLE $name$sub\n"; } elsif ($line =~ /CREATE VIEW ([a-z_0-9]*)(.*)/){ $name = "\`$1\`"; $sub = $2; $line = "DROP VIEW IF EXISTS $name;\nCREATE VIEW $name$sub\n"; } elsif ($line =~ /INSERT INTO \"([a-z_]*)\" VALUES(.*);/){ if ($open == 0) { $open = 1; $line_cache .= "INSERT INTO \`$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 "SET AUTOCOMMIT=1;\n";
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“sqlite如何遷移到mysql腳本”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!