MySQL database server has users to connect and use databases and tables. Users provide security for database operations. MySQL server comes with default users or in the operations, a lot of users are created. In this post, we will look at how to list these users.
Connect To MySQL Database
We will connect to the MySQL database server to list users. MySQL is a tool used to manage databases, tables, users and other parts of the database.
$ sudo mysql -u root
List Users From User Table
User information is stored in a database named
mysql which is used for internal MySQL Database operations. The user table holds all the database about users. We will use the following
SELECT query to get the only user named with
mysql> SELECT User FROM mysql.user;
Get Detailed User Information
As we see there is 3 user those are created by default. We have only listed usernames. We can get other information about users like below. We will use
SELECT query and list all information about users. But this will print information in a messy format as we can see below.
mysql> SELECT * FROM mysql.user;
Get User Host Restrictions
Users for MySQL have some restrictions to connect the MySQL server. Host column of user table hold which user can connect from which host. We can see host information like below.
mysql> SELECT USER,HOST FROM mysql.user;
In the screenshot, our MySQL server only accepts connection from localhost or all users.