Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

The title is self explanatory. Is there a way of directly doing such kind of importing?

like image 757
Marcel Avatar asked Oct 01 '08 04:10

Marcel


People also ask

How do I open a .BAK file in SQL?

Select "File" from the drop-down menu, then click the "Add" button. A file explorer window appears. Navigate to the BAK file, select it, and click "Open" to add the file to the backup medium.


1 Answers

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 Express edition, and open the SQL Server Powershell. There execute sqlcmd -S <COMPUTERNAME>\SQLExpress (whilst logged in as administrator)

then issue the following command.

restore filelistonly from disk='c:\temp\mydbName-2009-09-29-v10.bak'; GO 

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 

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.

like image 53
Richard Harrison Avatar answered Oct 06 '22 12:10

Richard Harrison