3

I have created an website using ASP.Net, a table using SQL Server, and I have published it to a provider.

What I want is to convert the MSSQL.sql file to Mysql.sql file. Is there any free software, or some code to convert it to SQL Server to MySQL ?

It would be much appreciated if someone could help me.

shA.t
  • 16,580
  • 5
  • 54
  • 111
Ishaq G
  • 59
  • 1
  • 2
  • 4
  • possible duplicate of [How to export MS SQL database to MYSQL?](http://stackoverflow.com/questions/3917081/how-to-export-ms-sql-database-to-mysql) – shA.t Jun 01 '15 at 06:41

3 Answers3

18

If you use phpMyAdmin to manage your MySQL (which almost all web hosts use) you can simply import the file in compatibility mode for MSSQL.

To do this, go to Import -> Choose your file -> Then select "MSSQL" from SQL compatibility mode: under Format specific options.

If you don't have phpMyAdmin already installed, you can download it from the site I linked above for free. The instructions on their website are very clear for installation.

After import, if you want to save a copy of the SQL file in MySQL's syntax simply use the Export feature.

ShaneC
  • 2,376
  • 4
  • 19
  • 27
  • 1
    i will try it but i am sorry i cant vote you because i am not having sufficient reputations to vote you – Ishaq G Sep 02 '11 at 04:50
  • 1
    That's fine! If my answer works for you, then selecting it as such will certainly be enough. Please let me know if you have any questions! – ShaneC Sep 02 '11 at 04:51
  • ok i will try but i am having another problem the problem is i am connecting my database using SQLDATASOURCE in Data from toolbox I want it to connect . it is getting an error the error is inserting is not supported in sqldatasource unless the insert command is specified – Ishaq G Sep 02 '11 at 04:55
  • Is this connection actually in your MSSQL code? Or is it a problem you're having actually connecting to your MS SQL database? If it's not in your code: Unfortunately I'm only passingly familiar with MS SQL. I recommend making a new question thread asking that specific question. – ShaneC Sep 02 '11 at 04:58
  • i am using this connection string to connect server=localhost;User Id=root;password=test;database=mydatabase – Ishaq G Sep 02 '11 at 05:00
  • Your answer is for the conversion in the opposite direction. OP asked about mssql > mysql – Anthony Jun 05 '15 at 06:22
  • @Anthony, this is for the mssql > mysql import. This doesn't convert the file, but imports directly into a MySQL database. – Jason Clark Jul 18 '16 at 11:49
1

When migrating databases from MS SQL to MySQL server it is often necessary to translate MS SQL queries according to MySQL syntax as well. Syntax of SQL queries in MS SQL and MySQL are similar but not identical. This article discovers 10 most popular differences between MS SQL and MySQL syntax. The target audience for this guide should have general database management knowledge and experience in composing SQL queries.

Sometime MS SQL table or column names are enclosed in square brackets in queries (e.g. if contains spaces or for some other reasons). MySQL does not allow square brackets around table of column names, they all must be replaced by ` symbol or cut off: [object] -> `object`.

MS SQL provides effective solution to avoid naming objects conflict and to manage user permissions on data access. This is schema, a logic container used to group and categorize objects inside the single database. When using schema the full name of database object in query may look like database.schema.object. However, there is no such semantic in MySQL, so all schema names must be cut off from queries.

CONVERT() function is used to convert an expression of one data type to another in MS SQL. In MySQL CONVERT() function converts text data between different character sets. However, there is equivalent function CAST(), so every occurrence of convert(type, expression) in MS SQL query must be replaced by cast(expression AS type) in MySQL query. LEN() function returns length of string expression in MS SQL. MySQL equivalent for this function is LENGTH(). MS SQL function DATEADD() adds interval to the specified part of the date. MySQL operator '+' can do the same as follows:

DATEADD(year,  1, $date$) -> $date$ + interval 1 year
DATEADD(month, 1, $date$) -> $date$ + interval 1 month
DATEADD(day,   1, $date$) -> $date$ + interval 1 day
where $date$ is an expression of DATE type.

Microsoft SQL and MySQL have different sets of date processing functions, although most of them can be replicated as follows:

DATENAME(month,   $date$) -> DATE_FORMAT($date$, '%M') or MONTHNAME(expression)
DATENAME(weekday, $date$) -> DATE_FORMAT($date$, '%W') or DAYNAME(expression)
DATEPART(year,    $date$) -> DATE_FORMAT($date$, '%Y')
DATEPART(month,   $date$) -> DATE_FORMAT($date$, '%m')
DATEPART(day,     $date$) -> DATE_FORMAT($date$, '0')
GETDATE()                 -> NOW()
GETUTCDATE()              -> UTC_TIMESTAMP()

where $date$ is an expression of DATE type.

MS SQL operator '+' allows to concatenate strings like this: 'string1' + 'string2'. In MySQL such expressions must be replaced by CONCAT('string1', 'string2'). MS SQL function CONTAINS(expression, template) searches for matches of template inside expression. MySQL has operator LIKE that implements the same semantics: expression LIKE %template% If MS SQL query contains 'TOP (100) PERCENT' pattern just cut it off when composing MySQL query. If there is another percentage amount in that pattern, it can be replace by the following code in MySQL (works in MySQL 5.0.7 and higher):

SET @amount =(SELECT COUNT(*) FROM %table name%) * %percentage% / 10; 
PREPARE STMT FROM '%original query% FROM %table name% LIMIT ?'; 
EXECUTE STMT USING @amount; 

Syntax of JOIN constructions are very similar in MS SQL and MySQL. The only difference is that MS SQL keyword WHERE is replaced by ON in MySQL. For example:

... table1 CROSS JOIN table2 WHERE condition

must be translated into

... table1 CROSS JOIN table2 ON condition
JustAMartin
  • 13,165
  • 18
  • 99
  • 183
ruchit
  • 230
  • 2
  • 10
0

PHPmyadmin option is nice for doing this job. But sometimes you will see errors while converting. We actually studied the DB structure of the MSSQL and wrote our own mysql statements based on it and did our unit testing and learned few things. So apart from conversion if you also want to do hands-on this is a good approach.

valueweaver
  • 483
  • 5
  • 11
  • 1
    Giving examples of what you had to hand on manually would be much more useful. Ideally, give your code with some basic comments, so that one can see which problem were encountered. – Balmipour Dec 05 '16 at 14:01