How to restore a SQL Server database from a backup file

Recently I volunteered to port a website from ColdFusion/SQL Server to PHP and MySql. But rather than getting the database snapshot as a SQL script, which would have been easy to migrate, I was given the database in the form of a SQL Server backup, which has two parts: an LDF log fie and an MDF data file.

Now not being particularly skilled in SQL Server, I had to hunt around for what to do with this. It turned out to be ultimately pretty easy. Just install SQL Server 2008 via the Web Installer, reboot, and then launch the administration interface and run this SQL statement to import the backup file as a database:

RESTORE DATABASE mydb FROM disk = 'C:\\path\\to\\mydb.bak'
WITH REPLACE, MOVE 'mydb_Dat' TO 'C:\\Program Files\\Microsoft SQL Server\\MSSQL10.SQLEXPRESS\MSSQL\\DATA\\mydbdat.mdf',
MOVE 'mydb_log' TO 'C:\\Program Files\\Microsoft SQL Server\\MSSQL10.SQLEXPRESS\\MSSQL\\DATA\\mydblog.ldf'

Then choose “Script to File” to output the database to an ordinary SQL script, which then can be imported into MySQL.

Leave a comment

Your email address will not be published. Required fields are marked *