Updated June 5, 2023
Introduction to MariaDB show users
MariaDB Show Users is a MariaDB command responsible for showing the list of users in a database server. The user tables save the user records, which include the usernames for login, passwords, user privileges, and other information. You will find a system table as MySQL. User in MariaDB as this is a split of MySQL, so this system table will still be available as mysql.user for the compatibility issue. Hence, running a query against MySQL. The user system table will return all of the Users created in the database MariaDB along with the information about these users.
Syntax
For the 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 a 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 runs this MySQL query:
SELECT * FROM mysql.user;
Please note that executing the above query will return and display all the columns present in the mysql.user table, resulting in a large output of results. You can trim down the fields to display specific information for practical purposes. Here’s an example of a trimmed-down query to fetch selected fields from the mysql.user table:
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:
- $ 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 below to display the user accounts 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 the previous one where it is allowed to logging for showing users together with their respective hostname 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 generate 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: 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 the “mysql” database, the MariaDB server provides information regarding the account users present in the “user” database table. To fetch the names of all user accounts in MariaDB, you can use the SELECT keyword statement to retrieve all table rows from the mysql.user table in the server. The query would be typed as follows:
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:
The above command has retrieved only two table columns, user and host, from the mysql.user server table. However, the mysql.user table still contains over 40 table columns, including password, update_priv, insert_priv, trigger_priv, select_priv, and others.
Generally, a user account in the MariaDB or MySQL server holds two sections where the first is the username, and the second one is the hostname. A user can implement the command as DESC mysql.user; Type statement to view the info about the database table columns. A user can execute a query to retrieve specific data from a table column once they know the column.
For 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 associated with databases, the next query will display data about all databases and related users:
SELECT User, host, db FROM mysql.db;
Output:
Here, the information of users accessing the database privilege level is saved in the table defined as mysql.db will be viewed. Hence, 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 on the server.
Also, you can yield a 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 the entire table columns present in the table mysql.user, but this makes the process of providing output a long execution; thus, there may be a need for trimming down a 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 in the mysql.user table:
DESC mysql.user;
Output:
Conclusion
- Hence, MariaDB Show Users is a MariaDB SQL command to draw the user accounts from table mysql.user or for the given MariaDB Database with associated privileges.
- Using this MariaDB Show User query command, one can view the users in MariaDB and the permissions provided to each.
Recommended Articles
We hope that this EDUCBA information on “MariaDB show users” was beneficial to you. You can view EDUCBA’s recommended articles for more information.