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.
Related
I'm trying to create stored procedures for my teammates who are non-technical and can't write MySQL queries on their own.
They are currently accessing the database through phpMyAdmin.
However, when I create stored procedures, my teammates are unable to execute them from phpMyAdmin. They see the procedures, but the "execute" command is absent and everything else is grayed out. Here's an example with a stored procedure named get_transaction_history:
To be sure, I gave my teammates the permission to execute the stored procedure with the following command:
GRANT EXECUTE ON PROCEDURE database.get_transaction_history TO 'teammate1'#'localhost';
And indeed, it's possible for them to execute the stored procedure through the CALL command. However, phpMyAdmin won't allow them to execute the stored procedure from its GUI. Yet, it claims that my teammates do have the EXECUTE option granted to them.
Anyone knows what's going on?
There are separate user privileges within phpMyAdmin to the DB itself.
Go to the phpMyAdmin homepage and click Privileges and check that the users have the privileges required to execute the stored procedure.
You are most probably facing this bug https://github.com/phpmyadmin/phpmyadmin/issues/14430
It was fixed in phpmyadmin version 5.10
Solution: check your version and upgrade.
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
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.
I have a MySQL stored procedure. I would like to have a stored procedure run some statements, then call a Java program. Then when the java program is complete, the stored procedure should finish.
The java program will connect to the database, do some analysis and then insert rows into other tables.
Is this possible?
Yes. Take a look at The MySQL UDF Repository and the sys_exec function. You could use this to launch your Java code in a new JVM.
After you get that installed here is how you run it: https://dba.stackexchange.com/a/39547/14506
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.