search

Home  >  Q&A  >  body text

Get the current user in MySQL Get the current user's MySQL username, no hostname required

I know that we can use the user() and current_user() functions to get the currently logged in user. But I only need users without hostname suffix. I can't seem to find any reference to the built-in MySQL function that just provides a username.

P粉340264283P粉340264283284 days ago382

reply all(1)I'll reply

  • P粉966335669

    P粉9663356692024-03-28 00:43:39

    You can use SUBSTRING_INDEX to return the string before the character (in this case "@")

    SELECT SUBSTRING_INDEX(current_user(),'@',1)

    So basically this way you avoid anything that is not the user part of current_user()

    reply
    0
  • Cancelreply