How can I view the list of user defined functions in mysql database using phpmyadmin.
Mysql database has been migrated from one server to another server and user defined custom functions are not working. I need to view the list of user defined function to check whether they exist in database or not.
Fatal error: db::execute() Could not execute: FUNCTION database.xxx does not exist (SQL: SELECT Function(field) FROM users in file.php on line xx
The following MySQL query will list the user-defined routines.
select * from information_schema.routines;
That will give you all the information about your custom functions/procedures:
select specific_name, definer from information_schema.routines where definer not like '%mysql%';
hope it helps!
Related
please suggest : for MYSQL databases object like procedure there is already a definer user . i required to add another user in to it so that both user can access and execute same procedure
I am using a hosted web service account that uses cpanel as its management system. When logged into phpmyadmin, I am trying to import an SQL file that contains tables and some procedures.
CREATE DEFINER=`root`#`localhost` PROCEDURE `getClientDashboardStatsMap` (IN `in_userID` INT) BEGIN
SELECT
rl.city,
rl.state,
rl.zip,
rl.longitude,
rl.latitude,
rl.timestamp,
count(rl.ID) as total
FROM
crowd.redemption_log as rl
JOIN
reward as r
ON
rl.rewardID = r.rewardID
WHERE
r.userID = 1
AND
rl.timestamp BETWEEN NOW() - INTERVAL 30 DAY AND NOW()
GROUP BY
rl.city, rl.state, rl.zip
ORDER BY
total DESC;
END$$
When I try to run this, I get an error about needing super user privileges to do so. Doing some searching, people suggested removing the definer line like so:
CREATE PROCEDURE getClientDashboardStatsMap (IN in_userID INT) BEGIN.
While this allows me to complete the import, I am running into another issue. The procedures are getting a default definer of cpaneluser#localhost. However, the database user that is set up is different than this user so the procedure has no permissions for things like select, update, delete. The database user is cpaneluser_dbusername, which is typical for hosted sites like this so you can associate databases with accounts.
How else can I get this procedures to run, under the correct user? I don't see any settings in PHPMYADMIN for privileges in order to run these as a super user.
There are two ways to solve this problem:
Log into phpmyadmin with the database user cpaneluser_dbusername. I am not familar with phpmyadmin and cpanel, so I'm not sure whether they provide you the option to change the user. You should check it out by yourself. I'm using MySQL Workbench and MySQL Administrator, they both privode me this option.
Grant privileges to cpaneluser#localhost. Such as:
GRANT ALL ON db_name.table_name TO 'cpaneluser#localhost';
It's better if you grant each privilege explicitly, e.g.: GRANT SELECT,INSERT,UPDATE,DELETE ON .... Check GRANT Syntax.
I'm currently having the latest version of MySQL(ver 8.0.2) and I'm trying to create a read-only View.
This is how my query looks like:
CREATE VIEW Emp_Salary3 AS
SELECT Empid, Ename, Date_Joined, Salary, Dcode
FROM Employees
WHERE Salary < 35000
WITH READ ONLY;
But then the response I got was:
Error Code: 1064. You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'READ ONLY' at line 5
Hence I checked the manual as well, it doesn't have a READ-ONLY option whatsoever. Is there a work around for this?
Any help could be appreciated.
MySQL doesn't support WITH READ ONLY for CREATE VIEW.
It is possible to create a read-only view in an indirect way: create an user that has the SELECT privilege on all tables and CREATE VIEW privilege then use this user to create the view and specify SQL SECURITY DEFINER in the CREATE VIEW statement:
CREATE
DEFINER = CURRENT_USER
SQL SECURITY DEFINER
VIEW Emp_Salary3 AS
SELECT Empid, Ename, Date_Joined, Salary, Dcode
FROM Employees
WHERE Salary < 35000
The line DEFINER = CURRENT_USER is not needed if you use the limited user to create the view.
Or you can use an admin user to create the view and in this case the line DEFINER = must contain the name of the user that will own the view.
The documentation explains:
MySQL checks view privileges like this:
At view definition time, the view creator must have the privileges needed to use the top-level objects accessed by the view. For example, if the view definition refers to table columns, the creator must have some privilege for each column in the select list of the definition, and the SELECT privilege for each column used elsewhere in the definition. If the definition refers to a stored function, only the privileges needed to invoke the function can be checked. The privileges required at function invocation time can be checked only as it executes: For different invocations, different execution paths within the function might be taken.
The user who references a view must have appropriate privileges to access it (SELECT to select from it, INSERT to insert into it, and so forth.)
When a view has been referenced, privileges for objects accessed by the view are checked against the privileges held by the view DEFINER account or invoker, depending on whether the SQL SECURITY characteristic is DEFINER or INVOKER, respectively.
This means the users of the view must have at least SELECT privilege for the view. Then, if the SQL SECURITY is DEFINER then the privileges of the DEFINER user are applied to the tables and views used in the view definition.
Clear IS_UPDATABLE in the INFORMATION_SCHEMA.VIEWS table after creating the view (see information-schema-views-table.html)
If the view has a join in it, then MYSQL will make that view read only (since it can't update composite views) but its a bit of an extreme measure
Recently, I deleted a user account in MySQL assigned to my former boss. Then, some database functions like deleting records from tables he made weren't working, giving the following error:
#1449 - There is no '*username*'#'localhost' registered
Now, I added a new user with the same name (and diff. password) and it works fine with no errors. But, is there way to resolve this without an placeholder user account?
Try replacing the DEFINER of the function
First login to mysql as root#localhost
Then, substitute root#localhost as the DEFINER
UPDATE mysql.proc SET definer='root#localhost'
WHERE definer = '*username*#localhost';
In fact, you can look at all DEFINERs like this:
SELECT COUNT(1) DefinerCount,definer,type
FROM mysql.proc GROUP BY definer,type;
This will show you how many functions and procedures each user owns. If any other the reported DEFINERs no longer exist or are invalid, you can make root#localhost inherit them.
Give it a Try !!!
I had to remove and re-add the triggers for the affected tables. (I used phpMyAdmin to do this).
I create stored procedure from mysql client terminal and everything is OK.
But when I try to call it i get this error message:
ERROR 1305 (42000): PROCEDURE XXX does not exist
After that i try to create it again without
DROP PROCEDURE IF EXISTS
statement and I get this:
ERROR 1304 (42000): PROCEDURE XXX already exists
What's wrong?
*THE PROBLEM WAS THAT MY DATABASE HAVE POINT (.) IN NAME *
*EXAMPLE: 'site.db' -> THIS IS WRONG NAME OF DATABASE AND MYSQL CAN'T FIND PROCEDURE !!!*
Possibly you have problems with consistency of your system databases after incorrect upgrade or something like that.
What are results for
select * from information_schema.ROUTINES where routine_name = 'xxx'
When you are define procedure using mysql client,
you could using root user (or user A).
Chances are you are using another user to call the store procedure,
let's said user B, it could causing some differences on the privileges
If this is the case, you can grant the access right
To view the current privilege, you can make use of this command
show procedure status;