Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Convert MySQL to SQL Server

Convert MySQL to SQL Server

As every migration between relational database management systems, transferring from MySQL to SQL Server involves processing such entries as schemas, data, indexes, constraints, views, stored procedures, functions and triggers. This whitepaper explores the migration process and contains some hints on choosing the proper tool to convert MySQL to SQL Server.

Here are the general steps required for the database migration:

  • Assess MySQL database: Understand the size, complexity, and dependencies of the source MySQL database. Identify any features or functionalities that are specific to MySQL and might require adjustments when migrating to SQL Server.
  • Plan the migration: Create a migration plan that outlines the timeline, resources and steps required to convert MySQL to SQL Server. Consider factors like data volume, downtime restrictions, and potential risks. Estimate maximum acceptable period of system downtime to switch the production environment.
  • Set up the SQL Server or Azure SQL environment: Install and configure SQL Server on the target server or Azure SQL cloud. Make sure you have the necessary permissions and access grants on MySQL and MS SQL servers to perform the migration.
  • Schema migration: Convert the database schema, tables, views, stored procedures, functions, and other MySQL database objects to SQL Server or Azure SQL with respect to correct type mapping and handling keywords. Ensure that the datatypes, constraints, and indexes are compatible with SQL Server.
  • Data migration: The goal of this step is to convert data from MySQL to SQL Server. There are several approaches for this task, such as using the SQL Server Migration Assistant (SSMA), writing scripts, or using dedicated data migration tools. It is extremely important to verify data integrity and consistency after data migration is completed.
  • Code migration: Review and modify all MySQL-specific patterns in queries and procedure language statements. Transform the code to make it compatible with SQL Server syntax paying special attention to conversion of built-in functions.
  • Testing and validation: Perform comprehensive testing to verify the functionality, performance, and accuracy of the migrated MS SQL database. Run various testing scenarios like data extraction and manipulation, test the application workflows.
  • Application Layer: Update the application configurations, connection strings, and any other relevant settings to point to the new SQL Server database.
  • Post-migration tasks: After the migration, monitor the SQL Server environment for any issues, performance bottlenecks, or errors. Optimize performance of the database when it is necessary and update the related documentation.

Types Mapping

Types mapping is important part of database schemas migration. MySQL and MS SQL have similar sets of supported data types, however some of them must be mapped properly as it is specified in the table below:

YEAR[(2 | 4)]NUMERIC(4)

AUTO_INCREMENT field property used by MySQL to automatically generate sequential integer numbers must be converted into IDENTITY in the target SQL Server database.

SQL Conversion

One of the top challenges when running MySQL to SQL Server database migration is conversion of SQL code in views, stores procedures, functions and triggers.

MySQL limited queries ‘SELECT … LIMIT number_of_rows’ must be converted into ‘SELECT TOP number_of_rows …’ MS SQL.

Unlike MySQL, SQL Server and Azure SQL requires all selected columns in ‘SELECT … GROUP BY …’ queries to be either under ‘GROUP BY’ clause or in aggregation functions.

There are specific MySQL functions that are not supported by SQL Server and so they must be replaced by equivalents according to this table:

CONCAT($arg1, $arg2, …)$arg1 + $arg2 + …
curdate(), CURRENT_DATECAST(getdate() AS date)
curtime(),CURRENT_TIMECAST(getdate() AS time)
DAY($date)DATENAME(d, $date)
DAYOFYEAR($date)DATENAME(dy, $date)
DAYNAME($date)DATENAME(dw, $date)
HOUR($date)DATENAME(hh, $date)
isnull($expression)$expression is null
now(), CURRENT_TIMESTAMPgetdate()
$expr like $temmplateCONTAINS($expr, $template)
timediff($date1, $date2)CAST($date1 – $date2 AS TIME)


As you can see from the guide above, database migration from MySQL to SQL Server is not a trivial task. Some software vendors offer special tools to automate major steps of the migration process.

The most common choice for partial automation of the database migration is Microsoft SQL Server Migration Assistant (SSMA) for MySQL. This is a standard tool coming as a part of SQL Server installation, it can convert MySQL to SQL Server through the following steps:

  • Connect to the source MySQL database and to the target SQL Server or Azure SQL
  • Migrate major entries from MySQL database (schema, data, indexes and constraints) to SQL Server or Azure SQL
  • Load the resulting entries into SQL Server or Azure SQL database
  • Migrate MySQL data to SQL Server or Azure SQL

Install and Connect. The latest version of SSMA for MySQL is available to download from the official Microsoft site. Launch SSMA and create a new project by clicking on “File” > “New Project”. In the project window, right-click on “Connect to MySQL” and enter the connection details (server name, port, username, and password) for MySQL server. Click “Connect”.

Configure. Next step is to configure SSMA. In the project window, click on “Project Settings”. Here, you can customize type mapping, schema and object conversion, and other migration settings.

Migrate Schemas. Right-click on the MySQL database and choose “Convert Schema”. This will convert table definitions from MySQL to SQL Server format based on the conversion settings specified on the previous step. Carefully review the conversion report to identify any issues that may require manual modifying the schema or adjusting the conversion settings accordingly.

Migrate Data. Right-click on the MySQL database and select “Migrate Data”. SSMA can either migrate all MySQL data or specify a filtering criterion. Once the data migration is complete, run comprehensive testing to ensure the integrity and consistency of SQL Server database.

Although SSMA can essentially help to convert MySQL to SQL Server, this method requires a lot of steps to set up the process. For migration projects requiring completely automated solution, it is recommended to use dedicated tools that are specially designed to fulfill the migration with just a few button-clicks. One of such software products is MySQL to SQL Server converter developed by Intelligent Converters vendor specializing in database migration and synchronization for years.

Key features of MySQL to SQL Server converter:

  • All modern versions of MySQL and SQL Server are supported including forks and DBaaS variations (Azure SQL, Amazon RDS, etc)
  • Schemas, data, indexes, constraints, foreign keys and views are converted
  • High performance of the data migration due to bulk reading and writing techniques
  • Option to customize type mapping and other attributes of every column as well as exclude selected columns from migration
  • Option to convert MySQL database into T-SQL script file (for those cases when direct connection to the target DBMS is not available)
  • Option to merge and synchronize existing MS SQL or Azure SQL database with MySQL data
  • Option to filter data for conversion and combine multiple tables in a single one using SELECT-queries

Visit official site of Intelligent Converters for learn more about how to convert MySQL to SQL Server.

Leave a Reply

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