How to import a SQL Server .bak file into MySQL?

原文链接   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'  
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值