user1720897
user1720897

Reputation: 1246

Get current user in MySQL without the hostname

I know that we can use the user() and current_user() function to get the currently logged in user. But I need just the user without the host-name suffixed. I cant seem to find any reference to built-in MySQL function that provides only the username.

Upvotes: 2

Views: 942

Answers (1)

David Valladares L.
David Valladares L.

Reputation: 138

You can use the SUBSTRING_INDEX that basically returns the string before a character (in this case '@')

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

So basically with this you will avoid anything that is not the user part from current_user()

Upvotes: 3

Related Questions