Definition of stored procedure:

A stored procedure is a segment of declarative SQL code, which is stored in the database catalog. A stored procedure can be invoked by a program, a trigger or even another stored procedure.

A stored procedure which calls itself is recursive stored procedure. Almost RDMBS supports recursive stored procedure but MySQL does not support it well. You should check your version of MySQL database before implementing recursive stored procedures.

Stored Procedure in MySQL:

MySQL is known as the most popular open source RDBMS which is widely used by both community and enterprise. However during the first decade of its existence, it did not support stored procedure, trigger, event…etc. Since MySQL version 5.0, those features have been added to MySQL database engine to allow MySQL to be more flexible and powerful.

Before starting the tutorial series about stored procedure, it is required that you have MySQL version  5.x+  installed in your computer or server.

Stored Procedures Advantages:

Stored procedure increases performance of application. Once created, stored procedure is compiled and stored in the database catalog. It runs faster than uncompiled SQL commands which are sent from application.

Stored procedure reduces the traffic between application and database server because instead of sending multiple uncompiled lengthy SQL commands statements, the application only has to send the stored procedure’s name and get the data back.

Stored procedure is reusable and transparent to any application which wants to use it. Stored procedure exposes the database interface to all applications so developers don’t have to program the functions which are already supported in stored procedure in all external applications.

Stored procedure is secured. Database administrator can grant the access right to application which wants to access stored procedures in database catalog without granting any permission on the underlying database tables.

Besides those advantages, stored procedure has its own disadvantages which you should be aware of before deciding using it.

Syntax & Execution:

You simply need to select the SQL option and type in your procedure remembering to set the Delimiter to // in the box underneath.

Here’s a stored procedure to try:

CREATE PROCEDURE sp_number_example_records()
BEGIN SELECT ‘Number of records: ‘, count(*) from example;
END//

where “example” is the table name.
On clicking “GO” the stored procedure is created and appears as a “routine” below the list of tables on the main “structure” page for the database.
Use the following SQL to call the Stored Procedure from your code:

CALL sp_number_example_records();
How-to-list-view-stored-procedure-in-phpmyadmin
If you want to list all stored procedures you can use this query
Select * from information_schema.routines where routine_type = ‘procedure’

A) In order to limit the result to a specific database:

select * from information_schema.routines
where routine_type = 'procedure' and routine_schema = 'your_db'
Details of particular stored procedure, show create procedure stored_procedure_name

Drop the stored procedure:

DROP PROCEDURE  producer_name  //(delimiter);
Or
DROP PROCEDURE IF EXISTS producer_name  $$

Creating the stored procedure:

CREATE PROCEDURE producer_name  ()
BEGIN
SELECT * FROM table_name;
END $$

To get the particular procedures:

select routine_definition from information_schema.routines where routine_schema = 'db_name' and routine_name = 'procedure_name';

Syntax of Like

CREATE PROCEDURE procedure_name(IN STORENUM INT)
BEGIN
SET @pattern = CONCAT('%',STORENUM,'%');
SET @sql = 'select * from table_name  where field_name like ?';
PREPARE stmt_name FROM @sql;
EXECUTE stmt_name USING @pattern;
DEALLOCATE PREPARE stmt_name ;
END;

Joins syntax:

BEGIN
SELECT * FROM  table1 t1  INNER JOIN table2 t2
ON t1.fieldname = t2.fieldname;
END