In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how sqlite migrates to mysql script, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.
The specific code is as follows:
#! /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 upprint "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"; Thank you for reading this article carefully. I hope that the article "SQLite how to migrate to mysql script" shared by Xiaobian will be helpful to everyone. At the same time, I hope that everyone will support it a lot. Pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.