'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.



Solution 1:[1]

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()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Valladares L.