Alternative to openquery delete for MySQL - mysql

I am running Microsoft SQL Server 2012 and am attempting to run an openquery delete command into a MySQL database:
delete openquery(MyLinkedServer, 'select * from table_to_delete_from');
This works, however is utterly, painfully slow to the point that it is unviable. The dataset involved is far too large, and doing the above requires that all of the MySQL data to be deleted must be fetched over VPN to the MSSQL server.
When running this command directly from the MySQL server, it is observed to be over 5x faster, which is viable.
How can I invoke a delete command from MSSQL over to the MySQL linked server without having to copy the datasets? Perhaps running a stored procedure of sorts on the MySQL side? Does that work with openquery?

Try this:
exec ('delete from table_to_delete_from') at MyLinkedServer

another case for SSIS, whenever i need to communicate to MYSQL. and insist to have truncate process on MYSQL table. i provide the procedure like below, :
CREATE PROCEDURE [dbo].[Usp_DeleteDynamicTable] #sourceTable nvarchar(max)
AS
BEGIN
DECLARE #SQL nvarchar(max)
SET #SQL='truncate table '+ #sourceTable
exec (#SQL) at MYSQL --MYSQL is my linked server names
END

Related

MIgrate Oracle DB data into Mysql db

There are multiple table in my Oracle DB that I plan to migrate into Mysql db.
The way I imagine is that
1.Go to each oracle table to execute some sort of cmd to generate the create statement that I can paste in my Mysql prompt.
However, due to my newbie knowledge in db, Does it really exist such simple cmd to do that?
If yes, can I even execute this idea batchly?

Ping website from MySQL Stored Procedure

I'm hosted a MySql database on Amazon RDS, and I'm looking to create a Stored Procedure that will ping my NAS at home and log the results to a table. I'm looking to create a log of my home internet outages.
I'm new to MySql and have no idea how to ping something from a Stored Procedure, and every search on google appears to be on how to ping a MySql server, not how to ping from a MySql stored procedure.
In mssql I can ping using the following method:
DECLARE #pingAddress VARCHAR(200) = 'ping www.google.ca'
EXEC master..xp_cmdshell #pingAddress
Is there anyway to achieve the same affect in MySql?
You shouldn't ping or do anything else outside the database in a stored procedure. Stored procedures are for manipulating data in MySQL.
If you want to log your home internet outages, there are services that do that for you, for example https://www.pingdom.com/free
If you prefer to do it yourself with custom code, write an application and host it on a small EC2 instance, or else run a Lambda function on a schedule or something like that.
Here's a blog about how one person did it with a Lambda: https://medium.com/#nzoschke/http-service-health-monitor-w-lambda-a9f475abbbf4
In a native MySQL unextended by user-defined functions, You Can't Do Thatâ„¢.
There may be a suitable set of user-defined functions if you must do it. But doing this sort of thing within a MySQL database is something zealously to be avoided.
Here is the UDF repository.
https://github.com/mysqludf

Importing Data into MySQL Database with SOURCE command

I have an existing MySQL database that I want to refresh with data from MSAccess database. I already have the SQL files created from the Access database with all of the insert statements. There are 3 SQL files, the largest of which is 8 MB.
The database is on an AWS server. In the past I've imported data using Sequel Pro from my Mac. This is very slow and subject to session failure.
Now I've figured out how to create the SQL files on my Windows VM and FTP them directly to the AWS server. My intent is to have a stored procedure truncate all tables and SOURCE the SQL files:
SOURCE /home/me/file1.sql ;
SOURCE /home/me/file2.sql ;
etc...
The stored procedure would also do any prep work on the tables and any post-import things needed like fixing foreign keys, etc.
The first problem is that this command doesn't work and causes syntax error:
set autocommit=0 ; source /home/me/CBD.sql ; commit ;
"source" is squiggly underlined and it says "missing colon". This happens whether or not I use the auto commit stuff.
Any ideas how I could do this?
Thanks...

Mysql run stored procedure after server restart

How can I run a stored procedure at server start-up? Is this possible?
I just want to run a SQL query.
You can use the init-file variable in your configuration file to run a text file containing SQL statements in it.

My script can't execute alter database command SQL Server 2008

I created a database then I create a procedure. When I want to alter this database, I got an error while altering this database says:
create/alter must be the first statement in a query batch
If you have more than one statement to run use 'GO' command:
alter database xyz ...
GO
INSERT INTO myTable() ...
GO
etc