I needed to transfer data from MSSQL (Microsoft SQL Server) to MySQL, and the best option for me was to write a python script that exported data as csv from MSSQL and then import this csv into mysql. This process is working well for me so far (and I am not looking for another way to do this).
Datatype conversion from MSSQL to MySQL is done like so:
MSSQL_MySQL_MAP = {
'nvarchar' : 'varchar',
'varchar' : 'varchar',
'bit' : 'boolean',
'smallint' : 'smallint',
'int' : 'int',
'datetime' : 'datetime',
'timestamp' : 'datetime',
'ntext' : 'longtext',
'real' : 'double',
'image' : 'BLOB',
'float' : 'float',
'money' : 'decimal',
}
The exported csv is imported into MySQL using the following command..
"""LOAD DATA INFILE '%s/%s' REPLACE INTO TABLE %s FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'"""
I have a situation where there is a "bit" datatype in MSSQL, and the exported CSV contains a True of False string like this:
22294,501,q4h,12 ,False,False,None,False,None,None,None,0,None,None
What is the best way to make MySQL understand that the True or False string is a boolean 1 or 0 and import it correctly? Currently, I get a following warning:
Warning: Incorrect integer value: 'False' for column 'system_code' at row 7
Is there a way to pass some parameters along with the load infile data that can accomplish this?
INSERT ... SELECT
to copy across translated data. – eggyal Jul 12 '13 at 17:07LOAD DATA
statement to read string values of 'False' and 'True' from a .CSV file and get that inserted as a 0 or 1 into a tinyint column, the only way I know to get that to work is with an expression, such as in your example, though for the benefit of future readers, I would be prone to writeSET col = IF(@var1='False',0,1)
– spencer7593 Jul 12 '13 at 17:14