Mysql run stored procedure after server restart - mysql

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.

Related

is there a way to execute a MySQL procedure automatically after server is up

I need to run a MySQL command every time the MYSQL server is up
I search for a start-up event or hooks but didn't find anything,
anyone knows the way to do it?
MySQL Server supports a configuration file directive init_file.
this variable names a file containing SQL statements to be read and executed during the startup process.
Basically, it's like your .bash_profile is for Bash shell instances. In that it contains commands that are executed once at the startup.
For example using init_file is required for enabling performance_schema instruments and consumers at startup, because that must be done with UPDATE statements at runtime, not with configuration file directives.

Run Sql Dump through stored procedure in mysql

Can we run the SQL dump command through a stored procedure/Trigger. I have to create a database on fly when certain events happen in the table.
I have achieved it on mysql command prompt or by workbench, however need a way to do it through procedure or trigger.

Alternative to openquery delete for 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

Making database backup using routines and procedures

I want to backup my MySQL database , can I do it by using procedures or routines. I mean if i call a procedure, and pass the path where the file is to be exported to the procedure, then the procedure will make the backup. How can I write such a procedure or routine.
Thanks!
The MySQL itself cannot make backup, you should do it from the outside, e.g. run mysqldump or another client program. But for your case (...using routines and procedures) you could try to use user-defined function, it may help you to run backup process.

mysql server: stored procedures - when do i create the stored procedures?

I found tutorials on creating a stored procedures on the net, I just don't understand when exactly do I need to execute the creation of the stored procedure.
do the stored procedures creation should be executed each time i restart my MySQL server ?
do I need to execute the stored procedures creation sql each time I start my application?
Stored procedures are persisted to the database, ie they will be there even after a restart of the database server. You create them once and then you run them as often as you need. Of course you may want to change them sometimes using an alter statement.