Get the current user in MySQL Get the current user's MySQL username, no hostname required
P粉340264283
P粉340264283 2024-03-27 08:31:44
0
1
339

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粉340264283
P粉340264283

reply all(1)
P粉966335669

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template