Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 312
burntsugar Avatar asked Jul 16 '09 03:07

burntsugar


People also ask

How can I see all MySQL users and passwords?

So for example, to show MySQL users' username, password and host, we'll modify the sql query to accordingly as such: mysql> select user, password, host from mysql. user; The above sql query will present you with a list of users and their respective user name, password and database host.

How can I see MySQL users in Ubuntu?

Show All MySQL Users A user account in MySQL consists of two parts: a user name and hostname. Use the desc mysql. user; statement to display information about the table's columns. Once you know the column name, you can run a query against a selected data.

How do I count the number of users in MySQL?

Counting the distinct userIDs can be done via: SELECT COUNT( DISTINCT intPosterID ) FROM tblQA; COUNT( DISTINCT field ) returns a count of the number of rows with different values for the given field - intPosterID in this case.


2 Answers

I find this format the most useful as it includes the host field which is important in MySQL to distinguish between user records.

select User,Host from mysql.user; 
like image 40
spkane Avatar answered Oct 30 '22 22:10

spkane


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.

like image 62
6 revs, 4 users 38% Avatar answered Oct 30 '22 23:10

6 revs, 4 users 38%