How to get a list of MySQL user accounts

I'm using the MySQL command line utility and can navigate through a database. Now I need to see a list of user accounts. How can I do this?

I'm using MySQL version 5.4.1 .


Use this query:

SELECT User FROM mysql.user;

Which will output a table like this:

+-------+
| User  |
+-------+
| root  |
+-------+
| user2 |
+-------+

As Matthew Scharley points out in the comments on this answer, you can group by the User column if you'd only like to see unique usernames.


我发现这种格式最有用,因为它包含了在MySQL中很重要的用于区分用户记录的主机字段。

select User,Host from mysql.user;

A user account comprises the username and the host level access.

Therefore, this is the query that gives all user accounts

SELECT CONCAT(QUOTE(user),'@',QUOTE(host)) UserAccount FROM mysql.user;
链接地址: http://www.djcxy.com/p/25046.html

上一篇: MySQL:如何选择所有时区的UTC偏移和DST?

下一篇: 如何获取MySQL用户帐户的列表