14

I want to create a stored procedure that INSERTs data from the MSSQL DB tables to my MySQL DB tables and vice versa. What do I need to do this?

I have looked into two solutions.

  1. Creating a linked server that will allow me to write and Query data from MySQL using stored procedures in MSSQL.

  2. MySQL Migration Toolkits. How ever this option seems like an overkill, since I only want to make a few INSERTS and SELECTS between the two

So I lay my trust in you and hope someone has had similar problems in the past and would be so kind and give me the best way to do this. Especially would the 1st option work?

Who ever helps me will have my undying gratitude.

EDIT: Forgot to mention they reside in different servers (running debian and MS)

5
  • Have you considered dumping the MSSQL data into csv, then import it into Mysql? Commented May 22, 2014 at 11:38
  • What version of SQL Server and MySQL are you using? Commented May 22, 2014 at 11:40
  • Dumping data would not work, since I need to triggered or timed procedure that will run every 5 min. It would create unneeded steps in the process. For the version info: SQL Server 2008 R2 Service Pack 2 and 5.5.37-0+wheezy1 protocol v: 10 Commented May 22, 2014 at 12:19
  • So this is not a one-time transfer? Commented May 22, 2014 at 12:25
  • No, it will be multiple times per hour. I need the 2 databases to be as identical as possible at all times 5-15 minute latency can be tolerated Commented May 22, 2014 at 12:26

1 Answer 1

21

If you want to do this regulary

  • LinkedServer and OPENQUERY could be good, if you are moving not too much records per cycle.
  • Integration Services Package is a good solution if you want to move lots of data (like thousands or millions of rows).

You can schedule them with SQL Server Agent.

The INSERT is a bit tricky with OPENQUERY:

INSERT INTO OPENQUERY (MYSQL, 'SELECT * FROM MySQL_Table')
SELECT * FROM dbo.SQLServer_Table

OR

INSERT INTO OPENQUERY (MYSQL, 'SELECT * FROM MySQL_Table')
VALUES ('Value1', 'Value2', ...)
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. So I can query MySQL tables with MSSQL T-SQL syntaxes without worrying too much about the compability after linking them? My biggest worry is writing the queries and then having to find out that some of the basic commands like INSERT, LEFT JOIN, UPDATE would not be compatible, because of the syntax issues...
You have to use the MySQL syntax in the OPENQUERY, and this stands to source components in SSIS to. T-SQL syntax won't work, inside the OPENQUERY, but outside of it, you should use T-SQL. I've edited the answer to show how to insert into MySQL with OPENQUERY
@Pred how to dump mssql data from one server to mysql of another server
@insoftservice That is something you usually cannot do easily and automatically. See the questions already asked in this topic. Also your question is extending the scope of the current one and should be asked separately. Please read How to Ask in help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.