原文链接 http://stackoverflow.com/questions/156279/how-to-import-a-sql-server-bak-file-into-mysql
The .BAK files from SQL server are in Microsoft Tape Format (MTF) ref:http://www.fpns.net/willy/msbackup.htm
The bak file will probably contain the LDF and MDF files that SQL server uses to store the database.
You will need to use SQL server to extract these. SQL Server Express is free and will do the job.
So, install SQL Server 2008 Express edition, use sqlcmd -S \SQLExpress (whilst logged in as administrator)
then issue the following command.
restore filelistonly from disk='c:\temp\mydbName-2009-09-29-v10.bak';
GO
--1.用此语句得到备份文件的逻辑文件名: RESTORE FILELISTONLY FROM DISK = N'd:\tempdb\olddb.bak' --备份文件存放路径 --看LogicalName,一般会有两个文件,如: --olddb --主逻辑文件名称 --olddb_log --日志逻辑文件名称
This will list the contents of the backup - what you need is the first fields that tell you the logical names - one will be the actual database and the other the log file.
RESTORE DATABASE mydbName FROM disk='c:\temp\mydbName-2009-09-29-v10.bak'
WITH
MOVE 'mydbName' TO 'c:\temp\mydbName_data.mdf',
MOVE 'mydbName_log' TO 'c:\temp\mydbName_data.ldf';
GO
--2.用以下语句还原数据库 RESTORE DATABASE new_db FROM DISK = 'd:\tempdb\olddb.bak' WITH MOVE 'olddb' TO 'd:\tempdb\newdb.mdf', MOVE 'olddb_log' TO 'd:\tempdb\newdb_log.ldf'
At this point you have extracted the database - then install Microsoft's "Sql Web Data Administrator".together with this export tool and you will have an SQL script that contains the database.
/*--对以上代码补充说明: RESTORE DATABASE 还原后数据库的名称 FROM DISK = '备份文件的路径\备份数据库名称.bak' WITH MOVE '主逻辑文件名称' TO '还原后的路径\还原后数据文件名称.mdf', MOVE '日志逻辑文件名称' TO '还原后的路径\还原后日志文件名称_log.ldf' */