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
Login to mysql as root and type following query
select User from mysql.user;
+------+
| User |
+------+
| amon |
| root |
| root |
+------+
I found his one more useful as it provides additional information about DML and DDL privileges
SELECT user, Select_priv, Insert_priv , Update_priv, Delete_priv,
Create_priv, Drop_priv, Shutdown_priv, Create_user_priv
FROM mysql.user;
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;
$> mysql -u root -p -e 'Select user from mysql.user' > allUsersOnDatabase.txt
Executing this command on linux prompt will first ask for the password of mysql root user, on providing correct password it will print all the database users to the text file.
Peter and Jesse are correct but just make sure you first select the mysql DB.
use mysql;
select User from mysql.user;
that should do your trick
MySQL stores the user information in its own database. The name of the database is MySQL
. Inside that database, the user information is in a table, a dataset, named user
. If you want to see what users are set up in the MySQL user table, run the following command:
SELECT User, Host FROM mysql.user;
+------------------+-----------+
| User | Host |
+------------------+-----------+
| root | localhost |
| root | demohost |
| root | 127.0.0.1 |
| debian-sys-maint | localhost |
| | % |
+------------------+-----------+