1

Most schemas' tables have last_updated_date and last_updated_by columns. I knew how to populate this in Oracle, but I am now using MySQL. Could someone please share how to get the mysql system variable that represents the currently logged in database user who is initiating an insert/update on a table?

I have googled and trolled the MySQL docs without much success...

THANK YOU!

Alexx
  • 3,572
  • 6
  • 32
  • 39

3 Answers3

3

Do this to get current user

select user()
juergen d
  • 201,996
  • 37
  • 293
  • 362
1

Run this:

select current_user ()

or

select user()

The MySQL documentation.

Ryan
  • 26,884
  • 9
  • 56
  • 83
  • Thanks for your answer - I did scour the mysql docs, but I just couldn't find the right thing. – Alexx Apr 10 '12 at 20:58
1
SELECT USER();

so for example...

update mytable set last_updated=USER() where id=1024;
ncremins
  • 9,140
  • 2
  • 25
  • 24