I cant see SQL Queries in MySQL Stored Procedure! - mysql

I have created numbers of stored procedures in MySQL through remote access. And those procedures worked well.
After a few days when I connected to Database through remote access. All stored procedures were alive but while was trying to call those procedures, I realized that SQL queries inside procedures had gone. Anyone knows the reason?

If SHOW CREATE PROCEDURE (see docs) isn't showing you the procedures (with SQL queries inside) you probably have some permission problems -- you need to be the owner of the procedure or have SELECT access to the mysql.proc table.

Related

mysql Stored procedures can be seen but cannot be executed by authorised user

I have created a small DB (MariaDB, in a XAMPP environment) for my group, and we are currently using phpmyadmin to interact with the DB. I have created users and given them different permissions depending on their specific usage needs; and this works fine for tables and views. However something seems wrong with stored procedures. I need to give the user Global SELECT and EXECUTE privileges in order for them to run them. If I do it at the database level procedures can be seen but cannot be executed.
I normally create the procedures from mysql workbench, and the look like this:
CREATE DEFINER=`root`#`localhost` PROCEDURE `proc_name`()
BEGIN
...
END
And users are like:user1#% although I have also tried creating user like user1#localhost but it doesn't help.
Any idea why this is happening? Does it have to do with the DEFINER?
Many thanks in advance!

Msql: on MYSQL Query Browser and MYSQL WorkBench

I am currently learning mysql workbench, but I have gotten a book that uses mysql query browser. However, when I am trying to download query browser, it is stated that it is discontinued. So I am currently using workbench. However, I find it difficult to create procedure. What is workbench equivalence of procedure? Thanks!
If you are referring to a stored procedure, then those are listed in the schema navigator on the left panel. Expand the desired schema to see sections for Tables, Views, Stored Procedures, and Functions. Right-clicking on Stored Procedures displays an option to "Create Stored Procedure".
Is this what are you looking for?
If so, write-click on Stored Procedures and select Create.
Otherwise please clarify your problem.

Where does mysql server store the stored procedure code?

In MS SQL Server, it lets you search across all the stored procedures for the instance of some text. Does this exist in MySQL?
This is useful for trying to understand what the impact of changing the schema would be.
"Show me all the code that involves TableX"
How would you query across all stored procedures?
The procedures are stored in table mysql.proc. The code is in column body.
So you could query:
SELECT db, name, body FROM mysql.proc WHERE body REGEXP '[[:<:]]tablename[[:>:]]'

Stored procedure gone missing in SQL Server 2008

I created a stored procedure which ran successfully but I can't seem to find the procedure in the usual place within the database and I can't execute the procedure in Excel but I can drop the procedure.
I am confused.
I have written many stored procedures and never had this problem. Thanks in advance.
Sounds like something I've done before: inadvertently added the stored proc to the master database rather than the database I thought I was working in.
Check the master database under System Databases.
To prevent this in the future, you may want to consider adding a use dbname statement in the script.

Grouping SQL queries

Sometimes an application requires quite a few SQL queries before it can do anything useful. I was wondering if there is a way to send those as a batch to the database, to avoid the overhead of going back and forth between the client and the server?
If there is no standard way to do it, I'm using the python bindings of MySQL.
PS: I know MySQL has an executemany() function, but that's only for the same query executed many times with different parameters, right?
This process works best on inserts
Make all you SQL queries into Stored Procedures. These eventually will become child stored procedures
Create Master Store procedure to run all other Stored Procedures.
Modify master Stored procedure to accept values required by child Stored Procedures
Modify master Stored procedure to accept commands using "if" statements to know which
child stored procedures to run
If you need return data from Database use 1 stored procedure at the time.