In Mysql, how does one display all users?
This is a frequently asked question for beginners of mysql. Today we will show you how to display all users in Mysql. We usually useShow databases can display all DATABASES,Show tables will display all data TABLES, so will you guess whether the command for displaying all users isWhat about show users? No, no, no. Now let's take a look at how to display all users.
Display All users in Mysql1. log on to the databaseFirst, you need to use the following command to log on to the database. Note that it must be a root user ~
## mysql -u root -p
2. query user tablesIn Mysql, there is a built-inMysql database stores some Mysql data, such as users, permission information, and stored procedures.A simple query statement is used to display all users.
SELECT User, Host, Password FROM mysql.user;
You will see the following information:
+------------------+--------------+--------------+| user | host | password |+------------------+--------------+--------------+| root | localhost | 37as%#8123fs || debian-test-user | localhost | HmBEqPjC5Y || johnsm | localhost | || brian | localhost | || root | 111.111.111.1| || guest | % | || linuxprobe | 10.11.12.13 | RFsgY6aiVg |+------------------+--------------+--------------+7 rows in set (0.01 sec)
If you want to increase or decrease the display of some columns, you only need to edit this SQL statement. For example, if you only need to display the user name, you can useSELECT User FROM mysql. user;. That's it. It's very easy. You can use this method to get all users. Please try it.
3. Show all users (no duplicates)Anyone familiar with Mysql knows thatThe effect of DISTINCT modification is to remove duplicate data, so we can use the following command to display all your Mysql users and ignore those users who only have different host names.
SELECT DISTINCT User FROM mysql.user;
The output of this command is as shown below:
+------------------+| user | +------------------+| root | | debian-test-user | | johnsm | | brian | | guest | | linuxprobe | +------------------+6 rows in set (0.01 sec)
From: https://www.rosehosting.com/blog/mysql-show-users/
Address: http://www.linuxprobe.com/mysql-show-all-users.html