How to query mysql users in linux

WBOY
Release: 2022-05-16 17:16:15
Original
9318 people have browsed it

How to query mysql users: 1. Use the "mysql -u root -p" command to log in to the root user of the database; 2. Use the "SELECT User, Host, Password FROM mysql.user" query statement to display Out all users in mysql.

How to query mysql users in linux

The operating environment of this tutorial: linux7.3 system, mysql8.0.22 version, Dell G3 computer.

How to query the mysql user in Linux

1. Log in to the database

First, you need to log in to the database using the following command. Note that you must be root User~

## mysql -u root -p
Copy after login

2. Query the user table

In fact, there is a built-in database named mysql in Mysql. This database stores some Mysql Data, such as users, permission information, stored procedures, etc., so we can display all users through the following simple query statement.

SELECT User, Host, Password FROM mysql.user;
Copy after login

You will see the following information:

+------------------+--------------+--------------+
| user             | host         | password     |
+------------------+--------------+--------------+
| root             | localhost    | 37as%#8123fs |
| debian-test-user | localhost    | HmBEqPjC5Y   |
| johnsm           | localhost    |              |
| brian            | localhost    |              |
| root             | 111.111.111.1|              |
| guest            | %            |              |
| linuxprobe       | 10.11.12.13  | RFsgY6aiVg   |
+------------------+--------------+--------------+
7 rows in set (0.01 sec)
Copy after login

If you want to increase or decrease the display of some columns, then you only need to edit this sql statement, for example, you only If you need to display the user's user name, then you can use

SELECT User FROM mysql.user;,
Copy after login

Expand knowledge

Display all users (not repeated)

Friends who are familiar with Mysql all know the function of the DISTINCT modification. By the way, it is to remove duplicate data, so we can use the following command to display all your Mysql users and ignore those users who only have different host names. .

SELECT DISTINCT User FROM mysql.user;
Copy after login

The output of this command is as shown below:

+------------------+
| user             | 
+------------------+
| root             | 
| debian-test-user | 
| johnsm           | 
| brian            | 
| guest            | 
| linuxprobe       | 
+------------------+
6 rows in set (0.01 sec)
Copy after login

Recommended learning: mysql video tutorial, Linux video tutorial

The above is the detailed content of How to query mysql users in linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template