I have a user that can be accessed from any host (we are currently in development). But I want to limit the execution of stored procedures only for localhost. The problem is that the
localhost
user is not recognized.
DROP USER IF EXISTS 'admin'@'%';
CREATE USER IF NOT EXISTS 'admin'@'%' IDENTIFIED WITH 'caching_sha2_password' BY 'my_password';
###########################
### STORED PROCEDURES ###
###########################
GRANT EXECUTE ON MY_DATABASE.* TO 'admin'@'127.0.0.1';
###########################
### SELECT ###
###########################
GRANT SELECT ON MY_DATABASE.MY_TABLE TO 'admin'@'%' WITH GRANT OPTION;
GRANT SELECT ON MY_DATABASE.MY_TABLE2 TO 'admin'@'%' WITH GRANT OPTION;
.
.
.
Executing this code throws me the next error.
[2024-11-23 20:59:09] You are not allowed to create a user with GRANT
Changing the host "solves" the error, but I want to limit the execution to localhost. I don't know if I just have to add a new user like this.
CREATE USER IF NOT EXISTS 'admin'@'127.0.0.1' IDENTIFIED WITH 'caching_sha2_password' BY 'my_password';
###########################
### STORED PROCEDURES ###
###########################
GRANT EXECUTE ON MY_DATABASE.* TO 'admin'@'127.0.0.1';
###########################
### SELECT ###
###########################
GRANT SELECT ON MY_DATABASE.MY_TABLE1 TO 'admin'@'127.0.0.1' WITH GRANT OPTION;
GRANT SELECT ON MY_DATABASE.MY_TABLE2 TO 'admin'@'127.0.0.1' WITH GRANT OPTION;
.
.
.
Or if there's another way without repeating the user definition
Asked by edjmir
(125 rep)
Nov 24, 2024, 03:07 AM
Last activity: Nov 24, 2024, 03:47 PM
Last activity: Nov 24, 2024, 03:47 PM