HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Can you "su -" in MySQL?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
canmysqlyou

Problem

If I have root on a mysql database and I want to drop privileges to that of a normal user, without using their password, can I do it? if so how? think # su - username on unix. Basically, I'm just looking to avoid needing their password to be them, so I can test their privileges at their user. In postgres I could simply allow an ident authentication on the system root user, to bypass password auth. The reason I need this is to be able to reproduce a users problem by being them, not being them will not allow an accurate reproduction. I can of course ask for their password, but that takes more time that bypassing it.

Solution

I just realized -- so long as you don't mind locking out the user while you log in --

  • back up the mysql.user table (well, the user's hashed password, at the very least)



  • set their password to something you know : UPDATE mysql.user SET password=PASSWORD('new password') WHERE user='username' AND host='hostname';



  • log in as them



  • set their password back to what it was : UPDATE mysql.user SET password='saved password hash' WHERE user='username' AND host='hostname';



... you may need to flush privileges; after manipulating the mysql.user table.

Context

StackExchange Database Administrators Q#526, answer score: 4

Revisions (0)

No revisions yet.