In Mysql, how does one display all users?

Source: Internet
Author: User

In Mysql, how does one display all users?

This is a frequently asked question for beginners of mysql. Today we will show you how to display all users in Mysql. We usually useShow databases can display all DATABASES,Show tables will display all data TABLES, so will you guess whether the command for displaying all users isWhat about show users? No, no, no. Now let's take a look at how to display all users.

Display All users in Mysql1. log on to the database

First, you need to use the following command to log on to the database. Note that it must be a root user ~

## mysql -u root -p
2. query user tables

In Mysql, there is a built-inMysql database stores some Mysql data, such as users, permission information, and stored procedures.A simple query statement is used to display all users.

SELECT User, Host, Password FROM mysql.user;

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)

If you want to increase or decrease the display of some columns, you only need to edit this SQL statement. For example, if you only need to display the user name, you can useSELECT User FROM mysql. user;. That's it. It's very easy. You can use this method to get all users. Please try it.

3. Show all users (no duplicates)

Anyone familiar with Mysql knows thatThe effect of DISTINCT modification 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;

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)

From: https://www.rosehosting.com/blog/mysql-show-users/

Address: http://www.linuxprobe.com/mysql-show-all-users.html


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.