Brief description Suitable for readers: Mobile development There are many syntax problems when migrating sqlite3 data to mysql. It is impossible to list all the problems at once. This article will try to list as many problems as possible, because everyone encounters different problems. Readers can use this article to predict in advance whether they will face any problems. Knowing what to expect can help avoid or reduce unexpected problems that may occur after migrating data. According to the list of problems, you can understand what problems you need to solve. I will also provide a solution for your reference. There is no one-size-fits-all solution to the migration problem, because everyone encounters different problems. If some conflicting problems exist in the solution at the same time, it will become a problem. Okay, let’s get straight to the point! Question List 1. Various variables dumped by sqlite3 are not recognized in mysql, such as (BEGIN TRANSACTION, COMMIT, etc.) 2. The sqlite database data cannot export the hidden field rowid 3. The data export format of sqlite database is incompatible with other databases, such as single quotes and double quotes 4. The exported sqlite data does not have column names, as shown in 5. Special symbol processing, such as escape character "\" 6. Table field length limits are different 7. Data writing efficiency Problem Solving First of all, you cannot use tools such as sqliteStudio and Navicat. Here, you can use shell commands to directly avoid content generation.
At the same time, using the shell method can be implemented with very little code. 1. Solve the problem that the field column name is not output Running the sqlite3 command "
Then get the column name through string replacement, as follows: Assume the variables are COLS = name, description 2. Solve the problem of single quotes and double quotes Running the sqlite3 command "
This method can solve the problem of single quotes and double quotes. Here we directly output single quotes uniformly. 3. Solve the problem that the default field rowid of sqlite3 cannot be displayed. Here, directly change rowid to id Set the current mode to .dump insert mode Running the sqlite3 command "
4. Use the shell string command to add the previously obtained column names to the following SQL statement After modification, it is as follows:
5. Escape character processing If there are escape characters in the data in the database, such as: This script mainly solves the above 1~5 problems. You can modify the script as needed. #!/bin/sh SQLITE=sqlite3 if [ -z "$1" ] ; then echo usage: $0 sqlite3.db exit fi DB="$1" TABLES=`"$SQLITE" "$DB" .tables` for TABLE in $TABLES ; do CREATE=`"$SQLITE" "$DB" "SELECT sql FROM sqlite_master WHERE type=\"table\" AND name = \"$TABLE\";"` echo $CREATE";" | cut -d'=' -f2 | sed "s/^CREATE TABLE $TABLE (/CREATE TABLE $TABLE (id int auto_increment primary key ,/g" COLS=`"$SQLITE" "$DB" "pragma table_info($TABLE)" | cut -d'|' -f2 ` COLS_CS=`echo $COLS | sed 's/ /,/g'` echo ".mode insert \n.header on \n select rowid as id,$COLS_CS from $TABLE;\n" | "$SQLITE" "$DB" | sed "s/^INSERT INTO \"table\"/INSERT INTO $TABLE /g" | sed 's#\\#\\\\#g' done Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of linux crm deployment code
>>: Element Plus implements Affix
MySQL Create Database After logging into the MySQ...
<br />Without any warning, I saw news on cnB...
Export database data: First open cmd and enter th...
1. concat() function Function: Concatenate multip...
Preface The Linux system is controlled by the sys...
HTML5 and jQuery implement the preview of local i...
Table of contents 1. Scene introduction 2 Code Op...
Table of contents Download and install JDK Downlo...
This article example shares the specific code of ...
I recently wrote a mobile page at work, which was...
Preface Basically, programmers in the workplace u...
Table of contents 1. Basic concepts and basic com...
Preface Let's get straight to the point. The ...
Table of contents Supports multiple types of filt...
When we want to add a shadow to a rectangle or ot...