raul prakash
raul prakash

Reputation: 113

Import .bak to MySQL (.sql)

I want to import a MS SQL SERVER2008 R2 database backup to MySQL Server. Any help on how I can convert the .bak to a .sql so that it can be imported to a MySQL database server?

I have read other threads regarding this but none have worked so far.

Thank you.

Upvotes: 0

Views: 12161

Answers (1)

Aaron Bertrand
Aaron Bertrand

Reputation: 280351

You can restore the database to a local version of SQL Server (you can download the free evaluation edition to do this):

http://msdn.microsoft.com/en-us/evalcenter/ff459612.aspx

Then you can use the import/export wizard in Management Studio to transfer your tables and other objects to your MySQL database (you may need additional ODBC drivers installed locally in order for SQL Server to establish a connection to MySQL).

EDIT

When restoring the database to SQL Server, don't use the clunky UI. Use an actual RESTORE DATABASE command. For example:

RESTORE DATABASE foo FROM DISK = 'c:\path\foo.bak';

Now, you may find that the original database was created with files placed on drives or folders that don't exist locally. So I suggest creating a very simple folder, temporarily, called c:\db_temp\, giving the Everyone account modify privileges, and then running the following:

RESTORE FILELISTONLY FROM DISK = 'c:\path\foo.bak';

This will return a resultset like:

LogicalName  PhysicalName
-----------  ------------
Foo          C:\...\foo.mdf
Foo_log      C:\...\foo_log.ldf

You need to build a RESTORE DATABASE command something like the following, based on the result above:

RESTORE DATABASE foo FROM DISK = 'c:\path\foo.bak'
  WITH MOVE 'Foo'     TO 'c:\db_temp\foo.mdf',
       MOVE 'Foo_log' TO 'c:\db_temp\foo_log.ldf';

Upvotes: 3

Related Questions