Introduction to MariaDB show users
MariaDB Show Users is a MariaDB command which is responsible to show the list of all users present in a database server. The user records are saved in the user tables that include the usernames for login along with password having user privileges and other information too. You will find a system table as mysql.user in MariaDB as this is a split of MySQL so this system table will be available still as mysql.user for the compatibility issue. Hence, running a query against the mysql.user system table will return all of the Users which are created in the database MariaDB along with the information about these users.
Syntax
For MariaDB Show User command which is used for retrieving all users available in MariaDB, we will execute the succeeding query statement as syntax:
SELECT User FROM mysql.user;
Let us discuss the details of mysql.user MariaDB table comprising the columns explained below:
- Host: User host that can be localhost, %, etc.
- User: Name of the user such as admin, root, or any specific one, etc.
- Password: It denotes the hashed value as password
- Authentication_string: It denotes the security column.
Initially, to view the list of users in the MariaDB database, it is required to login into your admin account as an administrative level user through the mysql command-line client, that running this MySQL query:
SELECT * FROM mysql.user;
It should be noted that the above query will return and show the entire columns present in the mysql.user table that creates for a lot of result output. Thus, for the practical purpose it may be trimmed down few fields for displaying somewhat like this one below:
SELECT host, user, password FROM mysql.user;
How to show users in MariaDB using various ways?
- In this MariaDB Show Users, initially login to your MariaDB/MySQL server using the mysql client as the root user, we will type the following query as:
- $ mysql -u root –p, where p is for the password associated with this username or also can type: $ mysql –u root –h localhost –p mysql. After the user admin has logged in you can execute different SQL queries provided below to display the user accounts either in MySQL or MariaDB database server.
- For the next step, you need to script the command at mysql>prompt for viewing the list items of user accounts available in the MariaDB database using the SELECT keyword and table mysql.user in the server as: SELECT User FROM mysql.user;
- After this, one can further use some commands similar to previous one where it is allowed to logging for showing users together with their respective host name or password: SELECT host, user, password FROM mysql.user; or, SELECT host, user FROM mysql.user;
- Again, for any repetition of database user names, we can avoid it by using the SQL code written as: SELECT User Distinct From mysql.user; where, the keyword as SELECT User DISTINCT in the query statement will result in generating the unique values.
- You can even yield the list of column fields associated and selected from the MariaDB mysql.user table through the SQL query command as follows: DESC mysql.user
- To discover the user rights granted we will implement the following command as: SELECT User, Db, Host From mysql.db;
- Next, one can even find the privileges provided to a distinct MySQL user as: SHOW GRANTS for ‘username’@’localhost’;
Examples
In MariaDB, the server provisions information about the account users present in the database table which is defined as user available in the mysql database. Therefore, to fetch the names of all user accounts in MariaDB by applying the SELECT keyword statement that will retrieve all table rows from this mysql.user table in the server, which is typed as:
SELECT User FROM mysql.user;
On execution the output will be as follows:
Similarly, we can also fetch the host names associated with the users using the query command as,
Output:
Again, run the query as:
SELECT User, Host FROM mysql.user;
Output:
Now, as you can see that from the mysql.user server table the above command has retrieved just two table columns i.e. user and host, but more than 40 table columns are still available or contained by the mysql.user table such as password, update_priv, insert_priv, trigger_priv, select_priv, etc.
Generally, a user account in the MariaDB or MySQL server holds two sections where first is username and the second on is the hostname. A user can implement the command as DESC mysql.user; type statement to view the info about the database table columns. So, once the table column is known a user can execute the query against any specific data of the table.
For an instance, suppose we want to fetch the information of user accounts in MariaDB including the password for its status as lively or expired, then we will implement the following query statement:
SELECT User, Host, password_expired, Password FROM mysql.user;
Output:
For retrieving information about users but associated to databases as the succeeding query will display data about all databases and related users:
SELECT User, host, db FROM mysql.db;
Output:
Here, the information of users those who have access to the level of databases privilege saved in the table defined as mysql.db will be viewed. Hence, with this we can discover the users who can manage a particular database with linked privileges. You can even use the WHERE clause to specify any database available in the server.
Also, you can yield list of all users from the table mysql.user in MariaDB with the query as follows with administrative privilege:
SELECT * FROM mysql.user;
Output:
Perhaps, this command will show entire table columns present in the table mysql.user but this makes the process of providing output a long execution thus, there may be need for trimming down few of the columns in practical implementation to view the users as required which can be achieved with the previous command statement as:
SELECT User, Host FROM mysql.user;
Using the below query you will fetch lists of table fields available in the mysql.user table:
DESC mysql.user;
Output:
Conclusion
- Hence, MariaDB Show Users is MariaDB SQL command to draw the user accounts from table mysql.user or for the given MariaDB Database with privileges associated.
- Using this MariaDB Show User query command one can view the users in MariaDB and also the permissions provided to each one.
Recommended Articles
This is a guide to MariaDB show users. Here we discuss How to show users in MariaDB using various ways along with the examples. You may also have a look at the following articles to learn more –