SQL Server not running queries on remote (Linked MySQL) server - mysql

For various horrible reasons, we've had to link SQL Server to a MySQL database using Linked Servers and an ODBC Data Source. The queries run fine, but looking at the query plans you can see that SQL Server is always doing a full table scan on the remote server - and then doing any joins/filtering at the SQL Server end.
How can we push these to the MySQL server instead?
Thanks
James

If you write your queries like this ...
select * from openquery
( myLinkedServer
,'Select * from mySQLTables where complicated joins/filters')
the joins/filters should happen remotely.

Related

AWS RDS - MySQL to SQL Server Linked Server - How To / Alternatives

Situation:
I have a MySQL database and SQL Server database, both in AWS RDS. SQL Server is 2016. I need to be able to select data from the MySQL db (in SQL Server). Before moving to RDS, I was able to accomplish this by creating a Linked Server in SQL Server using the MySQL Connector/ODBC.
My understanding is that ODBC driver must be installed/setup on the SQL Server (box), which isn't possible with RDS.
I looked at CLR, but not sure if that will be a viable route either (from reading online) with RDS (?).
Any ideas/experience on how I can select data from the MySQL database in SQL Server when both databases are housed in RDS? The solution doesn't need to be high speed and probably only needs to be used 100 to 200 times.
Only thing I can think of is to create a cache table in SQL, use my application layer to copy the MySQL data to the SQL cache table, and then use that cache table instead of MySQL directly.
Thanks!

SSIS linked to a mySQL server

in SQL server it's possible to link a mySQL server into msSQL and query it using SSMS for example. I want to try this and use SSIS to do some transformations and store all the data on this mySQL database.
\I read that there a several ways to link to mySQL into the msSQL server. OLE DB, mySQL ODBC etc etc.
2 questions:
Are there any limitations i might run into when i will use a combination of SSIS and mySQL instead of msSQL?
When i link a mySQL database into msSQL and i write a query in SSMS, do i write the queries in mySQL language or msSQL language. For example the difference in TOP and LIMIT
I have worked with a linked MySQL Server from SQL Server in the past and ran into some issues.
Querying MySQL from SSMS (SQL Server)
Once you have created a linked server you would imagine you should be able to use the four-part name and query the tables in MySQL but it doesnt allow you. for example you cannot do something like...
Select * from MySqlServer.DbName.Schema.TableName
For some reason it throws an error. So the question whether I can use T-SQL in SSMS to query a Linked MySQL Server? Nope, unfortunately not.
But alternatively Microsoft recommends using OPENQUERY to execute queries to a linked server.
When using OPENQUERY, SQL Server does not try to parse the query, it just sends it to the linked server as it is. which means you can/should be able to write MySQL in SSMS using OPENQUERY and it will work.
Using SSIS with MySQL
Even though SSIS is Microsoft's tool that comes with SQL Server but it is a proper ETL tool which can read data from multiple sources and send data to many types of destination.
Once you have used the appropriate driver to connect to MySQL and ported data in SSIS package , its really not relevant anymore, where the data came from? you would have access to all the SSIS tools and you should be able to use them as if the data was coming from a flat file, SQL Server or Excel sheet etc.
By using Linked Server in MSSQL you can also connect to mySql. for that you need to download ODBC drivers. and then you have to create new dsn and while creating dsn you have to insert mySql server's details. then you can further search regarding how to create Linked server on SQL SERVER. This option is very easy and Totally free. You can use OPEN QUERY FOR inserting, updating, deleting and also get the data out from mySQL.

Convert My SQL database to MS SQL database

I wanted to know if there is a way to convert a .sql file (My SQL backup) to .bak file (MS SQL backup)?
I am currently using MS SQL Server Management Studio Express 2005
Not really. An almost easy way to accomplish this is below.
Install a MySQL server and restore the .sql into it.
Then in your SQL Server create a linked server to the MySQL server.
You can then select the tables in the MySQL server over to SQL Server with something similar to below.
SELECT *
INTO [TABLENAME]
FROM OPENQUERY([LINKEDSERVERNAME], 'SELECT * FROM MYSQLTABLENAME')
Using INFORMATION_SCHEMA on the MySQL server, dynamic SQL, variables and a cursor you can loop through all the tables without coding for each table.
Don't forget to turn off the temporary MySQL instance. It only needs to be on while you're restoring/extracting from it.
And since *.bak are proprietary you have to create that once you've pulled all the tables into the SQL Server DB. Not sure if you really needed the BK or just the SQL Server Database.
While this may sound painful you're really talking less the 50 lines of code. Also, SQL Server will mostly handle the typing for you.

Slow Queries when using MySQL as a Linked Server from SQL Server (ODBC Connection)

I'm seeing very poor query performance when running a stored routine on a MySQL linked server from a SQL Server. The query runs from the SQL Server
select * from OPENQUERY(COGNOS, 'call reporting.sr_vendor_location_report(''2011-06-13 00:00:00'',''2012-01-18 00:00:00'',1,''0,1'',28,''(All)'',''(All)'',1,''(All)'')')
takes 15 seconds but if I check the mysql query log or run it on the server directly, I see that it only takes 7 seconds.
I've read elsewhere that MySQL ODBC connections are slow but I haven't seen any solutions suggested. I tried setting up mysql-proxy (just running it with a redirection - no LUA scripts) but didn't see any improvement. I'm using the MySQL ODBC Connector 5.1 and running MySQL version 5.5 on the server.
I'd be enormously grateful for any ideas on what to try.
UPDATE
It turns out that openquery runs each query twice on the mysql server, the first time presumably to get metadata. Is there any way to avoid this?
try to configure the provider to run out-of-process (right click on the provider and uncheck the allow in process box).
This is not exactly a setting related with performance, but I saw good performance gains in some cases with oracle, maybe it works with mysql too.
It turns out that using RPC instead of OPENQUERY solves the problem of SQL Server generating two queries.
e.g.
select * from OPENQUERY(COGNOS, 'call reporting.sr_vendor_location_report(''2011-06-13 00:00:00'',''2012-01-18 00:00:00'',1,''0,1'',28,''(All)'',''(All)'',1,''(All)'')')
becomes
exec('call ...') at COGNOS

Turning MySQL queries into SQL Server queries

I was given the task of building a database and the queries to interact with it.
They did not tell me what kind of database to use, so I chose the one I know: MySQL
Now It seems that the database has to be a SQL Server one and dead line for this task is within hours :(
I have already converted the database from MySQL to SQL Serverusing a program called DBConvert.
But now I have to change all my queries and I have no idea about SQL Server.
Is there any program/web that can do the magic, that can turn MySQL queties into SQL Serverones?
I'm learning about the SQL Serverenvironment so I'm installing the NET Framework and SQL Server 2005 Express, is that correct?
I'm looking for something like phpMyAdmin in SQL Server, is it SQL Server 2005 Express?
Sorry for all of this questioning, but as I said it is a matter of hours.
First of all the SQL Server 2005 Express is the MYSQL server and not like phpMyAdmin. For phpmyAdmin of SQL Server you can use MSSQL query analyzer (if you install MSSQL whole package this will be installed)
And I dont think so there is any program which will convert MYSQL queries to MSSQL queries.