how to get user in mysql code example

Example 1: show list of users in mysql

//To show all data use following query
select * from mysql.user;
// To show user and host use following query
select User,Host from mysql.user;

Example 2: mysql list users on ubuntu

SELECT User FROM mysql.user;

Example 3: display users in mysql

#display all user data
select * from mysql.user;
#display username and host
select user, host from mysql.user;

Example 4: show all users in mysql

mysql> select * from mysql.user;

Example 5: SELECT User,Host FROM mysql.user;

SELECT User,Host FROM mysql.user;
DROP USER 'testuser'@'localhost';

Example 6: mysql current user

-- mysql current user:
SELECT USER();
-- or
SELECT CURRENT_USER();

Tags:

Sql Example