How do i show all users in MySQL?

Source: Internet
Author: User

How do i show all users in MySQL?

This is a question that MySQL beginners often ask, and today we'll show you how to display all the users in MySQL. Usually we use show DATABASES in MySQL to display all the databases, showTABLES will show all the data tables, then you will not guess the command that shows all users is show users it? No, no, no, now let's take a look at how to show all the users.

Show all users in MySQL 1. Log in to the database

First of all, you need to log in to the database using the following command, note that must be root user Oh ~

# # Mysql-u Root-p
2. Querying user Tables

In MySQL in fact there is a built-in database named MySQL , the database is stored in some MySQL data, such as users, permissions information, stored procedures, and so on, we can use the following simple query statement to display all users.

SELECT User, Host, Password from Mysql.user;

You will see a message like this:

+------------------+--------------+--------------+| User             | host         | password     |+------------------+--------------+--------------+| root             |    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)

If you want to increase or decrease the display of some columns, then you just need to edit this SQL statement, such as you only need to display the user's user name, then you can use the SELECT user from mysql.user; You can get all the users in this way, just try it.

3. Show all users (do not repeat)

Friends who are familiar with MySQL know the role of DISTINCT , that is, to remove duplicate data, so we can use the following command to display all of your MySQL users and ignore those who are only the host name of different users.

SELECT DISTINCT User from Mysql.user;

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)

How do i show all users in MySQL?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.