Practical tutorial for importing data from sqlite3 to mysql, sqlite3mysql

Source: Internet
Author: User

Practical tutorial for importing data from sqlite3 to mysql, sqlite3mysql

Preface

Sqlite3 is small and lightweight, but does not support concurrent access. When the website concurrency is large, the database Request queue is long, which may cause the database operation to time out at the end of the queue and thus the operation fails. Therefore, you must switch to a database that supports concurrent access. To switch the database, you need to export the old data and then import it to the new database. However, the sqlite3 and mysql databases are not fully compatible. You need to make some adjustments before importing them to mysql. I encountered this problem in my recent work.

In a recent project, magenetico is used to capture magnetic links. Because sqlite3 is used, files become larger and larger, and distributed files are not supported. Therefore, you need to convert it into MySQL, before migration, You need to import 15 GB of data that has been crawled to MySQL. Let's take a look at the detailed introduction.

The method is as follows:

Dumping SQL statements from the sqlite3 File

sqlite3 database.sqlite3sqlite3> .output /path/to/dump.sqlsqlite3> .dumpsqlite3> .exit

Split files

When the file is large, it fails to be imported into half of the data. In this case, you need to split a new SQL file from the failed line.

awk '{if (NR>=6240863) print $0>"dump_part.sql"}' dump.sql

Mysql Parameter Modification

[mysqld]max_allowed_packet = 100M

SQL compatibility and symbol replacement

#1. Delete rows that do not contain insert into #2. Replace table name wrap #3. Replace hexsed '/insert /! D; s/"table1"/'table1'/; s/"table2"/'table2'/; s/, X/,/'dump. SQL

Import to MySQL

# Add the force parameter to prevent some problematic SQL statements from importing mysql-uroot-p-f magnet <dump. SQL

Reference

How To Use The SQLite Dump Command

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.

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.