Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a .bak file to .sql file

I have a asp script that I'm intending to write it with PHP so I have to get its database and use it.

I have the database as .bak file which I understood that it's a backup and I wanna change it to be .sql to import it in phpMyAdmin

I read about this matter in the web but I didn't find an accurate tutorial that goes through the whole process.

They are talking about mssql database but I didn't even reach this step..

Any help will be highly appreciated. Thanks in advance :)

like image 899
Hamo Avatar asked Sep 30 '12 14:09

Hamo


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.

How do I import a BAK file into mysql?

Right click on the 'databases' node click import- First select the BAK file then choose database - It automatically gets the database name from the loaded . bak file and puts it into the list. (to create the new database) Select that and click import.. Woohoo - 6 days later!


2 Answers

Note, all of this applies to MS SQL because .bak is a usually a MS SQL backup.

A .bak can't be converted to SQL directly -- it contains a backup of a database which does not have a clear relationship to SQL.

You could restore the backup and then use SQL Server tools and then use that to make some SQL to recreate the SQL server objects but not the dat.

From SQL Server Management Studio: Datbases item, right click "Restore Database" then from datbase right click script database.

This won't script the data.


The other option is to use RedGate's excellent tools, which should do everything you want.

http://www.red-gate.com/products/sql-development/sql-toolbelt/

like image 77
Hogan Avatar answered Nov 15 '22 16:11

Hogan


Most probably the .bak file is indeed a binary backup of a Microsoft SQL Server database (which is something completely different than MySQL).

So you will first need to install Microsoft SQL Server (Express) together with the SQL Server Management studio (I think there is a bundled download "SQL Server Express including Tools".

In the Management Studio you can then import the .bak file into a new database. Once the import is finished you can use it to create SQL script out of the database.

like image 35
a_horse_with_no_name Avatar answered Nov 15 '22 16:11

a_horse_with_no_name