Method 1: Back up SQL in mysql to import mysql Data to SQL Server. This method is suitable for scenarios with a small amount of data (you can consider how to avoid a large number of blob fields in your data or whether they do not exist ). Features: migration of small data volumes: convenient and quick. Step: 1. Use the mysql tool to back up SQL files. Here SQLyog is used.
Method 1: Back up SQL in mysql to import mysql Data to SQL Server. This method is suitable for scenarios with a small amount of data (you can consider how to avoid a large number of blob fields in your data or whether they do not exist ). Features: migration of small data volumes: convenient and quick. Step: 1. Use the mysql tool to back up SQL files. Here SQLyog is used.
Method 1: Back up SQL in mysql to import mysql Data to SQL Server. This method is suitable for scenarios with a small amount of data (you can consider how to avoid a large number of blob fields in your data or whether they do not exist ).
Features: migration of small data volumes: convenient and quick.
Step: 1. Use the mysql tool to back up the SQL file. Here I use SQLyog software.
2: process the backup SQL files (because these backup SQL files cannot be written or modified in the sqlserver parser ). Here is an example of SQLyog:
/*! 40101 set names utf8 */;
/*! 40101 SET SQL _MODE = ''*/;
/*! 40014 SET @ OLD_UNIQUE_CHECKS =@ UNIQUE_CHECKS, UNIQUE_CHECKS = 0 */;
/*! 40014 SET @ OLD_FOREIGN_KEY_CHECKS = @ FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS = 0 */;
/*! 40101 SET @ OLD_ SQL _MODE = @ SQL _MODE, SQL _MODE = 'no _ AUTO_VALUE_ON_ZERO '*/;
/*! 40111 SET @ OLD_ SQL _NOTES = SQL _notes, SQL _NOTES = 0 */;
/* Data for the table 't_ standard_check_unit '*/
Insert into 't_ standard_check_unit '('System _ id', 'unit _ TYPE_1', 'unit _ TYPE_2 ', 'unit _ TYPE_3', 'unit _ TYPE_4 ',
'UNIT _ TYPE_5 ', 'unit _ TYPE_6') values ('01 ', 9, 7, 6, 8, 4, NULL), ('02', 9, 8, 6, 5, 4, NULL), ('03', 9, 8, 5, 6, 4, NULL), ('04 ', 9, 8, 5, 6, 4, NULL), ('05', 9, 8, 6, 5, 4, NULL), ('06', 9, 8, 5, 6, 4, NULL), ('07 ', 9, 9, 9, 8, 4, NULL), ('08', 9, 8, 6, 5, 4, NULL), ('09', 9, 9, 8, 4, NULL );
/* Data for the table 't_ standard_system '*/
The above is the part of the backup SQL file:
Note: a: insert into 't_ standard_check_unit '('System _ id', 'unit _ TYPE_1', 'unit _ TYPE_2 ', 'unit _ TYPE_3 ',
Quotation marks in 'unit _ TYPE_4 ', 'unit _ TYPE_5', and 'unit _ TYPE_6 'are not supported in sqlserver, so they must be processed by a program.
Handler:
Public void switchSqlFile (File file) throws IOException {
BufferedReader bReader = new BufferedReader (new InputStreamReader (new FileInputStream (file), "UTF-8 "));
String filePathOld = file. getAbsolutePath ();
String filePath = filePathOld. substring (0, filePathOld. indexOf (".") + "_ switchFile"
+ FilePathOld. substring (filePathOld. indexOf ("."));
BufferedWriter bWriter = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (new File (filePath), "UTF-8 "));
String str = "";
While (str = bReader. readLine ())! = Null ){
If (str. contains ("create database "))
Continue;
If (str. contains ("USE 'q9 "'))
Continue;
If (str. toLowerCase (). contains (") values (") | str. toLowerCase (). contains (") values (") | str. toLowerCase (). contains (") values (") | str. toLowerCase (). contains (") values (")){
String ss = str. substring (0, str. toLowerCase (). indexOf ("values ("));
Str = ss. substring (0, ss. indexOf ("(")). replaceAll ("" ', "") + str. substring (str. toLowerCase (). indexOf ("values ("));
}
Str + = "rn ";
BWriter. write (str );
}
BReader. close ();
BWriter. close ();
}
This part of the program is not very intelligent. Here is only an example.
B: You can export the data of a table as a row. This way, the export recovery speed is fast (SQL optimization problem), but note: when the number of data rows in the table exceeds 1 kb, it cannot be used in SQL script parsing. In this case, select an insert statement to record a row. (Note: When a line is too long, the opening speed of the text editor will be very slow, so the second method is also convenient to view in the text editor .)
3: Use the processed SQL statement to import the SQL Server database.
Method 1: Open the SQL file directly and execute import in sqlserver.
Method 2: Use the sqlcmd command to import the SQL file. The function is the same as that of the source in mysql. For more information, see the previous article.
Method 2: Use the ODBC bridge to complete data migration:
To be continued .......................
Summary:
Mysql compatibility with sqlserver2008
I. Script compatibility issues
1: sqlserver does not support adding on delete restrict on update restrict to the foreign key constraint.
2: sqlserver2008 does not support drop table if exists XXX.
3: sqlserver2008 does not support the blob type. It must be changed to the image or text type.
Note: It is best to add constraints in the form of modification when creating a database. In this way, you can create no constraints during database recovery to avoid the troubles and efficiency problems caused by constraints.
It is best to organize the constraints to the bottom. And use tables and constraints instead of columns and constraints.