I have two Microsoft SQL Server database files named "xxx.mdf" & "xxx.ldf" and I want to import that database into MySQL so I can run queries against it using phpMyAdmin. How would I go about doing this?
-
1Do you already have SQL Server 2008 installed? If so, has the database (xxx.mdf) been attached to the SQL Server instance so you can see it in SQL Server Management Studio?– Gord ThompsonCommented Apr 7, 2013 at 13:48
-
No sir i dnt have SQL server installed in my pc..If you could provide me the link ..... The OS version of my pc is Windows 8 (64 bit ) .So please provide me the accurate download link..It will be very helpful for me– NafizCommented Apr 7, 2013 at 13:57
-
Check this solutions also you can download and install sql server 2008 Express and create sql files from your current files– AshianCommented Apr 7, 2013 at 14:49
2 Answers
The first thing to note is that an .sql
file is not a MySQL database. It is a script file containing SQL statements. You would run such a script against the database platform for which it was written (using the SQL dialect for a specific SQL database engine) to create the actual database.
Assuming that you are planning to do this all on a desktop machine with no software already installed, here is an overview of the steps to accomplish what you stated in your question. To describe every step in detail would make for a very long answer, so take this as a "roadmap" and start working through the steps. If you run into any particular difficulties that create a new question for that specific issue.
(Also, see the "Notes" at the bottom for a couple of possible alternatives.)
Install Microsoft SQL Server
If you are reasonably certain that the database in question is no larger that 10 GB and uses no Enterprise-level features (thanks, Jon!) then download SQL Server 2008 Express from here (thanks, Ashian!) and install it. Otherwise, download and install the (180-day trial) SQL Server Enterprise Evaluation Edition.
Attach the SQL Server database
Once SQL Server is installed, you need to "Attach" the existing database (.mdf/.ldf files) to the instance of SQL Server that you just created.
Install MySQL Server
To create and manipulate a MySQL database you need to have the MySQL Server software installed.
Install Internet Information Services (IIS)
phpMyAdmin is a web-based administration tool for MySQL, so it needs a web server environment in which to operate.
Install PHP
phpMyAdmin runs under PHP, so your IIS install must have that available, too.
Install phpMyAdmin
You need to install it if you're going to use it.
Install MySQL Workbench
MySQL Workbench will do the actual conversion from Microsoft SQL Server to MySQL.
Notes:
Of course, once you have SQL Server installed and the database attached, you could always "make multiple quer[ies]" against the database in SQL Server itself.
If the database really needs to be in MySQL (e.g., if you already have MySQL queries written or provided to you) but you only need to query the database locally, then a tool like HeidiSQL might allow you to avoid installing IIS, PHP, and phpMyAdmin.
In fact, HeidiSQL might be able to do the conversion for you (e.g., by doing an export from SQL Server and an import into MySQL), in which case you could use it instead of MySQL Workbench.
-
2I would actually recommend installing SQL Server Enterprise Evaluation Edition (free 180-day trial) for a couple reasons: (a) this is only temporary (I assume), and (b) although it's unlikely, if there are any Enterprise Edition features persisted in the database (such as table partitioning), Express will refuse to attach, thus wasting valuable time. If a longer-term solution is necessary, I would buy a copy of Developer Edition (~US$50), which includes all features found in Enterprise but isn't licensed to be used in production. Commented Apr 7, 2013 at 17:13
-
@JonSeigel Thanks for your insights! I will update my answer. Commented Apr 7, 2013 at 17:16
my fav app for manage my databases is http://www.heidisql.com/
and you can also Exporting databases as SQL Query then run query in mysql
.
-
1Have you tried this before? Do you know from experience that T-SQL scripts created by Microsoft SQL Server will work when run against MySQL? (I don't know because I've never actually tried it, but I really doubt that it will work.) Commented Apr 7, 2013 at 15:37
-
yes, but with a editor and with
Find-Replace
you can make your mysql query..– mehdiCommented Apr 7, 2013 at 15:51 -
Is it possible to import mdf and export sql or csv with this kit HeidiSQL.???– NafizCommented Apr 7, 2013 at 16:50
-
Is it possible to import mdf and export sql or csv with this kit HeidiSQL.???If possible then please describe the procedure .– NafizCommented Apr 7, 2013 at 16:56
-
so you can attach your
.mdf
file to sql server then open it with HeidiSQL and export to a mysql db directly– mehdiCommented Apr 7, 2013 at 17:04