Can't alter MySql routine - mysql

I am logging in with my main DB user, into Phpmyadmin page/ workbench remote access application and I have permissions issues.
It all started when I tried to alter routines that I have stored in the DB. when trying to alter those routines from the workbench applications nothing just happens.
I can call these routines and execute them, but not alter or get to the scripts.
I searched for hours in distinct forums and get some answers regarding grant access commands
but then I got again permissions issues with error #1142 , command denied to user(main user).
I am really lost here, and already lost hours of work in order to get to the scripts of my routines.
one last note - I have created these routines while I was connected with the same user but from different remote connection (different IP address).
Would really appreciate the help.

here is a solution how I fixed this:
1) Add "mysql" database to the user, you are logged in with
Advice: now you can alter functions and procedures
2) Add the global privilege "SUPER" to your user
Advice: otherwise you will get the following error if you save the procedure/function: "ERROR 1227: Access denied; you need (at least one of) the SUPER privilege(s) for this operation"

CREATE DEFINER = 'admin'#'localhost' PROCEDURE account_count()
SQL SECURITY INVOKER
BEGIN
SELECT 'Number of accounts:', COUNT(*) FROM mysql.user;
END;
See the above example.
You need to login using super user and change the definer parameter in the procedure based on your new username and hostname. The same definer who created can edit the stored procedure.

Related

Deleting the MySQL 'root' user on purpose triggers "Access denied" for other MySQL accounts

I have one MySQL 5.6 running in production with a legacy root account that is used for years. As part of a hardening program, I wanted to remove this root account - make it available via another account not named root basically.
After creating another account named adminacc with full accesses on the DB, I deleted the account named root.
Right after this action, all (adminacc could still log in) my others accounts could not log in anymore receiving the below message
SQL State 28000 Error 1045: Access denied for user 'XXX'#'wathever' (using password: YES)
I granted the denied account full accesses on the DB - without success.
I finally recreated my root account (with the same previous password, not sure if relevant here) and my DB accounts went back.
How can it be there is a dependency between an account (would it be the initial root) and another in MySQL? Would it be because I created this other account while connected as root user? Or the other account is trying to query a view created by the root account? I believe not, just throwing thoughts trying to understand.
What I found the most weird in my senario is that the connection from the denied account was not completely denied. When testing the connection from a Windows odbcad32.exe utility, it succeedded! But whenever used in app context (running from the same windows host), it failed.
I did run a capture and here is the output (this is from the app context)
You can see the login actually happens well; few queries are executed properly (basically init statments at session opening like SET NAMES utf8 or SET SQL_AUTO_IS_NULL = 0).
Then the error is thrown when the user tries to execute a SELECT against one of the DB views.
Nota: I found no recommendation from MySQL docs to not delete the initial root account. Nothing describing such situation. Browsing a bit on the internet, I found this previous StackOverflow question but it remained unanswered.
As explained by Akina, this issue was tied to Stored Object Access Control in MySQL. Not only this applies to procedures, functions, triggers but views as well, read this
For stored routines (procedures and functions) and views, the object
definition can include an SQL SECURITY characteristic with a value of
DEFINER or INVOKER to specify whether the object executes in definer
or invoker context. If the definition omits the SQL SECURITY
characteristic, the default is definer context.
My errors actually appear whenever a view was called (and because all of the views were created via this root account and with the SQL SECURITY set to DEFINER - default behavior).
Making a lot of sense now. That being said, the MySQL error message could have been more descriptive on the actual issue!

When creating MySQL Stored procedures, how can I avoid the setting the DEFINER with an ip that keeps changing?

Whilst a long time MS SQL Server user, MySQL is new to me. I've created an Internet site for a charity using PHP and MySQL. When I created the stored procedures in MySQL Workbench I didn't use the DEFINER parameter, so they are all set as the logged in account at the time, e.g. mysqluser#xx.xx.xx.xx The IP address was my home ip at the time, which has now changed. I now can't edit the stored procedures as I don't have the appropriate privileges apparently. Is this simply an issue with how Cpanel is used to create the MariaDb and the users, or can I alter how I write the stored procedures so that my IP is no longer important? I'm also worried that PHP login details might somehow stop working. Any help to relieve this confusion would be appreciated.
I'm not sure what solutions there are for your current circumstance, but to answer your question
You could use:
CREATE DEFINER = 'admin'#'localhost' PROCEDURE account_count()
or
CREATE DEFINER = 'remoteuser'#'%' PROCEDURE some_func()
As long as you have remote access to the host machine, you'd still be able to say for example ssh then login mysql as 'admin'#'localhost'.
Or login as 'remoteuser' regardless of your IP address, mind that wildcard host would not work if a user with the same name had a hostname that's more specific. Also privileges need to be granted to these users beforehand.
For DHCP, you can also do something with wildcard such as:
CREATE DEFINER = 'user'#'192.168.%' PROCEDURE do_sth()

The user specified as a definer does not exist - GRANT doesn't fix

After years of no problems with my PHP webapp running MySQL 5.5 on the backend, suddenly today I'm having permissions problems.
Whenever I try to run an INSERT statement (either from PHP or from Workbench or Heidi), I get this error message: The user specified as a definer ('my_user'#'1.2.3.%') does not exist
One symptom is that INSERT statements cannot be executed by my PHP nor by remote clients such as Workbench or Heidi. I have tried various solutions suggested by:
MySQL error 1449: The user specified as a definer does not exist
Error: 1449, "The user specified as a definer ('root'#'localhost') does not exist"
Everything points to running a GRANT statement. I have tried various GRANTs as suggested, but I always get this error:
Access denied for user
It seems like my permissions got corrupted or something. So I created a brand new DB user inside BlueHost control panel on my VPS and gave full privileges. I get the same exact errors on this brand new user.
BlueHost support has no idea what to do.
Some Stack articles say to go mess around with TRIGGERS or STORED PROCS permissions - but I don't have any of these types of objects. Simple INSERT statements cause this error, and perhaps UPDATEs as well, but I'm not sure of that at this moment.
The user has FULL PRIVILEGES, as always.
What else can I try? Is there some way to fix corrupted permissions? I can run SELECT statements with no problems.
I tried connecting to the DB with root (using the same pwd as I use when connecting to WHM), but it didn't like my password or maybe the user in general. I never set up root as a specific user against this DB and I'm not sure that's a good idea. I have always used a specific user created just for this DB. Again, past 5 years no problems at all. The DB has not been upgraded, no DB changes, no user changes, nothing.
I sort of solved it. I ended up creating a new database with a different name, and created a new admin user to go with it. Then I ran my db backup/dump script against it. Everything works perfectly again, with this new DB. The old DB is still jacked.
I'm thinking that permissions got corrupted in the old database.

access denied ;you need super privilege for this operation in sql query browser

I am very new to sql. Now i am trying to host an application in amazon which uses a database. so i create an ec2 instance and use sql query browser connecting to rds instance in amazon.I import the .sql dump file and executed that. i am getting error in this statement...
CREATE DEFINER='root'#localhost 'PROCEDURE'delete_user_message'(in id varchar(20))
as Access denied ;you need (atleast one of) the super privileges for this operation .error (1227).How can i fix this and create the database
The issue is that in RDS you don't get SUPER privileges, which is required to create a procedure owned by another user. To make this work, all you need to do is remove the DEFINER portion of your statement. Then it will automatically use the current user.

stored procedures in phpmyadmin server

I have created stored procedures in **MySQL database on my local machine and when i generate the script to run it on the host server i have this error**
#1227 - Access denied; you need the SUPER privilege for this operation
and this is the code
CREATE DEFINER = `User_name`#`host_name` PROCEDURE `InsertOrder`
and this user_name take all the privilege ,so any one can help please?
As the manual says:
If you do not have the SUPER privilege, the only permitted user value is your own account, either specified literally or by using CURRENT_USER. You cannot set the definer to some other account.
You must either issue the command using an account which has the SUPER privilege, or else change the DEFINER to your current user account (which is the default if it's omitted).