Skip to main content

Fixed: "ERROR 1356 (HY000): View 'sys.innodb_lock_waits' references invalid table(s) or column(s) or function(s)" in MySQL

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

Reading sys.innodb_lock_waits failed with ERROR 1356 (HY000): View 'sys.innodb_lock_waits' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them. The view isn't broken. The end of that long message is the real reason: the account lacks a right.

What I Was Doing​

I'd set up an account to look at locks on MySQL 9.7.4 in Docker, and given it SELECT on sys, since all I wanted to do was read:

mysql: root session
GRANT PROCESS ON *.* TO 'lock_viewer'@'%';
GRANT SELECT ON performance_schema.* TO 'lock_viewer'@'%';
GRANT SELECT ON sys.* TO 'lock_viewer'@'%';

Then, as that account:

mysql: as lock_viewer
SELECT waiting_pid, blocking_pid FROM sys.innodb_lock_waits;

What I Expected​

An empty result, or a row for each wait.

What I Got​

Output
ERROR 1356 (HY000) at line 1: View 'sys.innodb_lock_waits' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them

A SELECT from sys.innodb_lock_waits failing with ERROR 1356 (HY000): View references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them.

What I Checked​

Whether the view was damaged. Root could read the same view without a problem, so it wasn't.

What the view uses. The sys views call stored functions to format their results. Running a function takes EXECUTE, and SELECT doesn't include that.

Why It Happens​

MySQL uses one message for two very different situations: a view whose tables have gone, and an account that can't use what the view uses. It runs the view's functions as the invoker, so the account reading it needs the right to run them.

The Fix​

Add EXECUTE on sys:

mysql: root session
GRANT EXECUTE ON sys.* TO 'lock_viewer'@'%';

After the Fix​

Output (with one more query, to show the account's rights are working)
+-------+
| locks |
+-------+
| 0 |
+-------+

The same account reading the views without an error, with a locks count of 0.

No error. The first query returned no rows because nothing was waiting, so the client printed nothing for it, and the second one printed a count.

Common Mistakes​

MistakeWhat happensDo this instead
Reading the first half of the messageIt looks as if the view is brokenRead to "lack rights to use them"
Reinstalling the sys schemaThe view was never brokenGrant EXECUTE
Granting root's rights to fix itFar too muchGrant SELECT, EXECUTE on sys.*

Troubleshooting​

SymptomLikely causeFix
Still ERROR 1356 after EXECUTEPROCESS or performance_schema rights are missingGrant all three
The same error on your own viewA table or column it uses is gone, or the account lacks a rightRun the view's query by hand
SELECT command denied insteadNo SELECT on sysERROR 1142

Conclusion​

ERROR 1356 on a sys view usually means a missing right, not a broken view. The views call functions, so the account needs EXECUTE as well as SELECT.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.