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.
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.
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.
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.
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With