- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is `definer` required when creating a MySQL stored procedure?
No, definer part is not compulsory when you are creating a stored procedure. It is used when you want to create a definer.
Check all the user and host from the MySQL.user table −
mysql> select user,host from mysql.user;
The following is the output −
+------------------+-----------+ | user | host | +------------------+-----------+ | Manish | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % | | mysql.sys | % | | root | % | | Adam Smith | localhost | | User1 | localhost | | am | localhost | +------------------+-----------+ 9 rows in set (0.03 sec)
Here, let us create a definer as Adam Smith. The query to create a stored procedure is as follows −
mysql> delimiter // mysql> CREATE DEFINER = 'Adam Smith'@'localhost' procedure Sp_Definer() -> begin -> select 'Hello MySQL'; -> end; -> // Query OK, 0 rows affected (0.14 sec) mysql> delimiter ;
Call the stored procedure using CALL command. The syntax is as follows −
CALL yourStoredProcedureName();
Call the above stored procedure.
mysql> call Sp_Definer();
The following is the output.
+-------------+ | Hello MySQL | +-------------+ | Hello MySQL | +-------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.01 sec)
Advertisements