How to get a list of user accounts using the command line in MySQL?

前端 未结 15 1810
自闭症患者
自闭症患者 2020-12-22 14:35

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

相关标签:
15条回答
  • 2020-12-22 15:01

    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.

    0 讨论(0)
  • 2020-12-22 15:01

    This displays list of unique users:

    SELECT DISTINCT User FROM mysql.user;
    
    0 讨论(0)
  • 2020-12-22 15:02
    SELECT * FROM mysql.user;
    

    It's a big table so you might want to be more selective on what fields you choose.

    0 讨论(0)
  • SELECT User FROM mysql.user;
    

    use above query to get Mysql Users

    0 讨论(0)
  • 2020-12-22 15:04

    to avoid repetitions of users when they connect from different origin:

    select distinct User from mysql.user;
    
    0 讨论(0)
  • 2020-12-22 15:05

    If you are referring to the actual MySQL users, try:

    select User from mysql.user;
    
    0 讨论(0)
提交回复
热议问题