Kevin
Kevin

Reputation: 3631

MySQL execute as user or impersonate

In MySQL, is there a way to execute a query as a specific user to test table permissions? Is there a way to impersonate a user execution context when you are connected with a higher privileged account?

In the MSSQL world, one would use EXECUTE AS login = 'username', followed by your SQL Statements, then finally a REVERT, to close the impersonation.

Is there something similar in MySQL?

Upvotes: 7

Views: 6662

Answers (2)

Ashwini M
Ashwini M

Reputation: 149

You must go to home page, change settings of Local instance or whatever Schema you are using. There you need to change the username. If you are looking to run the query where you have logged in with your credentials and wants to run other query with other credentials then check the 'proxy users' in MySQL.

I hope this helps.

Upvotes: 0

Cristian Porta
Cristian Porta

Reputation: 4433

Personally I have never tried before, but you can take a look at the "Mysql Proxy User" available starting from MySQL 5.5.7

The plugin may request that the connecting (external) user be treated as a different user for privilege-checking purposes. This enables the external user to be a proxy for the second user; that is, to have the privileges of the second user. In other words, the external user is a “proxy user” (a user who can impersonate or become known as another user) and the second user is a “proxied user” (a user whose identity can be taken on by a proxy user)

Also you can write your own authentication plugins for proxy users

... Here another post that explain this kind of behaviour "MySQL Proxy Users – SU emulation"

Upvotes: 1

Related Questions