SHOW CREATE PROCEDURE inconsistent results with perl DBI - mysql

Piping "SHOW CREATE PROCEDURE foo" into mysql results include the complete procedure definition in a column labeled "Create Procedure". However,
$dbh->selectrow_hashref("SHOW CREATE PROCEDURE foo");
results in $ref->{'Create Procedure'} being undef, with other columns correctly populated.
Both executed on the same machine with the same credentials.
Does anyone know why?

This is what you would see if the user you connect as doesn't have permission to see the procedure. Try using the same user on the command line and I'd guess you will see NULL for the Create Procedure column.
You appear to need select privilege on mysql.proc to see procedure bodies.

Related

ERROR 1146 (42S02): Table 'mysql.proc' doesn't exist while calling a stored procedure

I am using this thread -
Rename a mysql procedure
to rename a stored procedure
Here upon trying the command as shown in the answer -
UPDATE `mysql`.`proc`
SET name = '<new_proc_name>',
specific_name = '<new_proc_name>'
WHERE db = '<database>' AND
name = '<old_proc_name>';
I get the error -
ERROR 1146 (42S02): Table 'mysql.proc' doesn't exist while calling a stored procedure
Here regarding the other questions regarding mysql.proc does not exit, none address the specific problem of calling a stored procedure.
The mysql.proc table was removed in MySQL 8.0. See No more mysql.proc in MySQL 8.0
You can use information_schema.routines to get information about stored procedures. But this is a read-only view, you can't update it. So I don't think there's any simple way to rename procedures any more. You may be able to use dynamic SQL to define the procedure with the new name using this information.
EDIT:
Unfortunately, the above is not possible just in MySQL, because CREATE PROCEDURE can't be executed using PREPARE, and information_schema.routines doesn't contain all the information needed to recreate the procedure. You could do it in an external language by performing a SHOW CREATE PROCEDURE query and then replacing the name to form a new query.
Recommend avoid fiddling with any mysql table directly.
Use show create procedure old_proc_name
And then create procedure new_proc_name ....
And drop the old drop procedure old_proc_name

show create procedure procedure_name into a variable in MySql

Here We want to Create a script to copy the store procedure from one DB to Another DB in MYSQL,
show create procedure procedure_name
This command show the store procedure definition of Store Procedure.
How to store the output of the above command in temp table.
Threat it like a select statement and fetch the result (which is one row and one column).
Fetching the result to the script and pushing it back is probably the easiest way. If you don't like that approach a server side cursor could do it.

mysql users can see stored procedures?

example:
A non-super user has been granted execute on a procedure that inserts into table "a". That user will see the database that table "a" is in with a "show databases", but will not be able see table "a" with a "show tables". But that same user can see basic procedure info with a "show procedure status".
This is for auditing and I would like to have the audit process as obscured as possible. If a user is granted execute on a procedure must that user have the ability to see the procedure? And must they be able to see the database that the procedure touches?
If you are the owner of the procedure or if you have access to mysql.proc table you can see the definition of the procedure as stated here.
So you would create the procedure as super and set DEFINER CURRENT_USER (so the procedure executes as super). Then make sure super has access to the table but that no one else does. That should protect both the table and the source but leave it possible to call on the procedure.
And it don't have to be super, can be any user that has access to the table.

STORED PROCEDURE does not exist

I create stored procedure from mysql client terminal and everything is OK.
But when I try to call it i get this error message:
ERROR 1305 (42000): PROCEDURE XXX does not exist
After that i try to create it again without
DROP PROCEDURE IF EXISTS
statement and I get this:
ERROR 1304 (42000): PROCEDURE XXX already exists
What's wrong?
*THE PROBLEM WAS THAT MY DATABASE HAVE POINT (.) IN NAME *
*EXAMPLE: 'site.db' -> THIS IS WRONG NAME OF DATABASE AND MYSQL CAN'T FIND PROCEDURE !!!*
Possibly you have problems with consistency of your system databases after incorrect upgrade or something like that.
What are results for
select * from information_schema.ROUTINES where routine_name = 'xxx'
When you are define procedure using mysql client,
you could using root user (or user A).
Chances are you are using another user to call the store procedure,
let's said user B, it could causing some differences on the privileges
If this is the case, you can grant the access right
To view the current privilege, you can make use of this command
show procedure status;

Trouble creating stored procedure

I'm messing around with stored procedures for the first time, but can't even create a simple select! I'm using phpMyAdmin and this is my SQL:
DELIMITER //
CREATE PROCEDURE test_select()
BEGIN
SELECT * FROM products LIMIT 10;
END //
DELIMITER ;
After submitting that, my localhost does some thinking for a loooong time and eventually loads a page with no content called /phpmyadmin/import.php. After reloading phpMyAdmin and trying to invoke the procedure:
CALL test_select();
I get a "PROCEDURE doesn't exist" error. Any ideas?
Try to use the delimiter field of phpMyAdmin, as shown in the screenshot below:
Simply put the following in the query window:
CREATE PROCEDURE test_select()
BEGIN
SELECT * FROM products LIMIT 10;
END
In addition note that there is bug in some older versions of phpMyAdmin, which can cause an error when you call stored procedures that contain SELECT statements from phpMyAdmin.
You may want to check out the following posts for further reading:
MySQL Stored Procedures not working with SELECT (basic question)
How do I write an SP in phpMyAdmin (MySQL)?
This bug effects only phpMyAdmin, and you would still be able to call the stored procedure from anywhere else.