MySQL database server has users to connect and use databases and tables. Users provide security for database operations. MySQL server comes with default users or in the operations, a lot of users are created. In this post, we will look at how to list these users.
MySQL数据库服务器具有用户连接和使用数据库和表的功能。 用户为数据库操作提供安全性。 MySQL服务器附带有默认用户或在操作中创建了许多用户。 在这篇文章中,我们将研究如何列出这些用户。
连接到MySQL数据库 (Connect To MySQL Database)
We will connect to the MySQL database server to list users. MySQL is a tool used to manage databases, tables, users and other parts of the database.
我们将连接到MySQL数据库服务器以列出用户。 MySQL是用于管理数据库,表,用户和数据库其他部分的工具。
$ sudo mysql -u root
![Connect To MySQL Database](https://img-blog.csdnimg.cn/img_convert/fa13844371ced0384751db9ab7da117d.png)
从用户表中列出用户(List Users From User Table)
User information is stored in a database named mysql
which is used for internal MySQL Database operations. The user table holds all the database about users. We will use the following SELECT
query to get the only user named with user
column.
用户信息存储在名为mysql
的数据库中,该数据库用于内部MySQL数据库操作。 用户表包含有关用户的所有数据库。 我们将使用以下SELECT
查询来获取唯一一个以user
列命名的user
。
mysql> SELECT User FROM mysql.user;
![List Users From User Table](https://img-blog.csdnimg.cn/img_convert/95c4a5d99ef0638c772273494af2b7a1.png)
获取详细的用户信息(Get Detailed User Information)
As we see there is 3 user those are created by default. We have only listed usernames. We can get other information about users like below. We will use SELECT
query and list all information about users. But this will print information in a messy format as we can see below.
我们看到有3个用户是默认创建的。 我们只列出了用户名。 我们可以像下面那样获取有关用户的其他信息。 我们将使用SELECT
查询并列出有关用户的所有信息。 但这将以混乱的格式打印信息,如下所示。
mysql> SELECT * FROM mysql.user;
![Get Detailed User Information](https://img-blog.csdnimg.cn/img_convert/8df535d93b3d6c05f0ba5d98ed73d945.png)
获取用户主机限制(Get User Host Restrictions)
Users for MySQL have some restrictions to connect the MySQL server. Host column of user table hold which user can connect from which host. We can see host information like below.
MySQL用户对连接MySQL服务器有一些限制。 用户表的主机列包含哪个用户可以从哪个主机连接。 我们可以看到如下主机信息。
mysql> SELECT USER,HOST FROM mysql.user;
![Get User Host Restrictions](https://img-blog.csdnimg.cn/img_convert/fcffc7a918cca22f3e2b5db0b5aec6f1.png)
In the screenshot, our MySQL server only accepts connection from localhost or all users.
在屏幕截图中,我们MySQL服务器仅接受来自localhost或所有用户的连接。