如何列出MySQL数据库用户?

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
Connect To MySQL Database
连接到MySQL数据库

从用户表中列出用户(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
List Users From User Table
从用户表中列出用户

获取详细的用户信息(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
Get Detailed User Information
获取详细的用户信息

获取用户主机限制(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
Get User Host Restrictions
获取用户主机限制

In the screenshot, our MySQL server only accepts connection from localhost or all users.

在屏幕截图中,我们MySQL服务器仅接受来自localhost或所有用户的连接。

LEARN MORE  How To List MySQL Tables with "show tables" SQL Query
了解更多如何使用“显示表​​” SQL查询列出MySQL表

翻译自: https://www.poftut.com/list-mysql-database-users/

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值