0

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.

raul prakash
  • 113
  • 1
  • 3
  • 10
  • 2
    possible duplicate of [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) – mmmmmm Mar 12 '12 at 12:40
  • Hey Mark I have read that post. The problem is that when I try to restore the .bak through MS SQL, I get an error when I select my .bak file. MSSQL error: "Specified cast is not valid.(SqlManagerUI). – raul prakash Mar 12 '12 at 20:14
  • Then make that the question - the current question is a duplicate – mmmmmm Mar 12 '12 at 20:22

1 Answers1

3

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';
Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490
  • I tried this as well but MSSQL doesn't load from the .bak file. Produces an error saying "Specified cast is not valid. – raul prakash Mar 12 '12 at 20:17
  • At what point did SQL Server say "Specified cast is not valid"? Can you do a better job of describing exactly what you did? – Aaron Bertrand Mar 12 '12 at 20:18