
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL Stored Procedure DEFINER=`root`@`%` is not working in localhost?
First of all, you need to check the host. The host can be ‘localhost’ or ‘%’. Check the existence of user accounts with host −
mysql> select user,host from MySQL.user;
This will produce the following output −
+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % | | mysql.sys | % | | root | % | | @UserName@ | localhost | | Adam Smith | localhost | | David | localhost | | James | localhost | | John | localhost | | John Doe | localhost | | User1 | localhost | | am | localhost | | hbstudent | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | +------------------+-----------+ 17 rows in set (0.00 sec)
Now, we are going to change the definer for user Bob and host is ‘%’. Following is the query to create a stored procedure with definer −
mysql> DELIMITER // mysql> CREATE DEFINER=`Bob`@`%` PROCEDURE `Message`() BEGIN select "Hello World"; END // Query OK, 0 rows affected (0.14 sec) mysql> DELIMITER ;
Now call the stored procedure with the help of CALL command −
mysql> call `Message`();
This will produce the following output −
+-------------+ | Hello World | +-------------+ | Hello World | +-------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.01 sec)
- Related Articles
- Is `definer` required when creating a MySQL stored procedure?
- Working with WHERE IN() in a MySQL Stored Procedure
- Rename Root @ localhost username in MySQL?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- MySQL stored procedure return value?
- MySQL stored-procedure: out parameter?
- View stored procedure/function definition in MySQL?
- Implement DELETE query in MySQL stored procedure
- Set conditions in a MySQL stored procedure
- Display description of MySQL stored procedure
- What is stored procedure and how can we create MySQL stored procedures?
- What is the usage of “@” symbol in MySQL stored procedure?
- Implement If else in stored procedure in MySQL?
- MySQL “not a variable or NEW pseudo-variable” message. What is this error in my Stored Procedure?
- Create a stored procedure with delimiter in MySQL

Advertisements