如何在 MySQL 中使用命令行获取用户帐户列表?

发布于 2024-07-26 22:22:45 字数 99 浏览 3 评论 0原文

我正在使用 MySQL 命令行实用程序,并且可以浏览数据库。 现在我需要查看用户帐户列表。 我怎样才能做到这一点?

我正在使用 MySQL 版本 5.4.1。

I'm using the MySQL command-line utility and can navigate through a database. Now I need to see a list of user accounts. How can I do this?

I'm using MySQL version 5.4.1.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(17

静谧 2024-08-02 22:22:45

使用此查询:

SELECT User FROM mysql.user;

它将输出如下表:

+-------+
| User  |
+-------+
| root  |
+-------+
| user2 |
+-------+

正如 Matthew Scharley 在此答案的评论中指出,如果您只想查看唯一的用户名,可以按用户列进行分组。

Use this query:

SELECT User FROM mysql.user;

Which will output a table like this:

+-------+
| User  |
+-------+
| root  |
+-------+
| user2 |
+-------+

As Matthew Scharley points out in the comments on this answer, you can group by the User column if you'd only like to see unique usernames.

彩虹直至黑白 2024-08-02 22:22:45

我发现这种格式最有用,因为它包含主机字段,这在 MySQL 中对于区分用户记录很重要。

select User,Host from mysql.user;

I find this format the most useful as it includes the host field which is important in MySQL to distinguish between user records.

select User,Host from mysql.user;
宫墨修音 2024-08-02 22:22:45

用户帐户包括用户名和主机级别访问权限。

因此,这是给出所有用户帐户的查询

SELECT CONCAT(QUOTE(user),'@',QUOTE(host)) UserAccount FROM mysql.user;

A user account comprises the username and the host level access.

Therefore, this is the query that gives all user accounts

SELECT CONCAT(QUOTE(user),'@',QUOTE(host)) UserAccount FROM mysql.user;
最佳男配角 2024-08-02 22:22:45

为了避免用户从不同来源连接时重复:

select distinct User from mysql.user;

To avoid repetitions of users when they connect from a different origin:

select distinct User from mysql.user;
仙女山的月亮 2024-08-02 22:22:45

MySQL将用户信息存储在自己的数据库中。 数据库的名称是MySQL。 在该数据库内,用户信息位于一个名为 user 的表(数据集)中。 如果想查看MySQL用户表中设置了哪些用户,请运行以下命令:

SELECT User, Host FROM mysql.user;

+------------------+-----------+
| User             | Host      |
+------------------+-----------+
| root             | localhost |
| root             | demohost  |
| root             | 127.0.0.1 |
| debian-sys-maint | localhost |
|                  | %         |
+------------------+-----------+

MySQL stores the user information in its own database. The name of the database is MySQL. Inside that database, the user information is in a table, a dataset, named user. If you want to see what users are set up in the MySQL user table, run the following command:

SELECT User, Host FROM mysql.user;

+------------------+-----------+
| User             | Host      |
+------------------+-----------+
| root             | localhost |
| root             | demohost  |
| root             | 127.0.0.1 |
| debian-sys-maint | localhost |
|                  | %         |
+------------------+-----------+
弱骨蛰伏 2024-08-02 22:22:45

如果您指的是实际的 MySQL 用户,请尝试:

select User from mysql.user;

If you are referring to the actual MySQL users, try:

select User from mysql.user;
亣腦蒛氧 2024-08-02 22:22:45
SELECT * FROM mysql.user;

这是一个很大的表,因此您可能希望对选择的字段更有选择性。

SELECT * FROM mysql.user;

It's a big table so you might want to be more selective on what fields you choose.

[旋木] 2024-08-02 22:22:45

以 root 身份登录 MySQL 并输入以下查询:

select User from mysql.user;

+------+
| User |
+------+
| amon |
| root |
| root |
+------+

Log in to MySQL as root and type the following query:

select User from mysql.user;

+------+
| User |
+------+
| amon |
| root |
| root |
+------+
简单 2024-08-02 22:22:45

mysql.db 表在确定用户权限方面可能更重要。 我认为如果您在 GRANT 命令中提到一个表,就会在其中创建一个条目。 就我而言,当用户显然能够连接和选择等时, mysql.users 表显示没有用户权限。

mysql> select * from mysql.db;
mysql> select * from db;
+---------------+-----------------+--------+-------------+-------------+-------------+--------
| Host          | Db              | User   | Select_priv | Insert_priv | Update_priv | Del...

The mysql.db table is possibly more important in determining user rights. I think an entry in it is created if you mention a table in the GRANT command. In my case the mysql.users table showed no permissions for a user when it obviously was able to connect and select, etc.

mysql> select * from mysql.db;
mysql> select * from db;
+---------------+-----------------+--------+-------------+-------------+-------------+--------
| Host          | Db              | User   | Select_priv | Insert_priv | Update_priv | Del...
み青杉依旧 2024-08-02 22:22:45

我用它来对用户进行排序,因此允许的主机更容易发现:

mysql> SELECT User,Host FROM mysql.user ORDER BY User,Host;

I use this to sort the users, so the permitted hosts are more easy to spot:

mysql> SELECT User,Host FROM mysql.user ORDER BY User,Host;
九命猫 2024-08-02 22:22:45

Peter 和 Jesse 是正确的,但请确保首先选择“mysql”数据库。

use mysql;
select User from mysql.user;

那应该可以达到你的目的。

Peter and Jesse are correct, but just make sure you first select the "mysql" database.

use mysql;
select User from mysql.user;

That should do your trick.

眼泪也成诗 2024-08-02 22:22:45

这将显示唯一用户的列表:

SELECT DISTINCT User FROM mysql.user;

This displays the list of unique users:

SELECT DISTINCT User FROM mysql.user;
清晨说晚安 2024-08-02 22:22:45
gt;  mysql -u root -p -e 'Select user from mysql.user' > allUsersOnDatabase.txt

在 Linux 命令行提示符下执行此命令将首先询问 MySQL root 用户的密码。 提供正确的密码后,它将把所有数据库用户打印到文本文件中。

gt;  mysql -u root -p -e 'Select user from mysql.user' > allUsersOnDatabase.txt

Executing this command on a Linux command line prompt will first ask for the password of MySQL root user. On providing the correct password it will print all the database users to the text file.

作死小能手 2024-08-02 22:22:45

我发现他的一个更有用,因为它提供了有关 DML 和 DDL 权限的附加信息

SELECT user, Select_priv, Insert_priv , Update_priv, Delete_priv, 
       Create_priv, Drop_priv, Shutdown_priv, Create_user_priv 
FROM mysql.user;

I found his one more useful as it provides additional information about DML and DDL privileges

SELECT user, Select_priv, Insert_priv , Update_priv, Delete_priv, 
       Create_priv, Drop_priv, Shutdown_priv, Create_user_priv 
FROM mysql.user;
孤独难免 2024-08-02 22:22:45
SELECT User FROM mysql.user;

使用上面的查询来获取 MySQL 用户。

SELECT User FROM mysql.user;

Use the above query to get the MySQL users.

屋檐 2024-08-02 22:22:45

要查看你的用户,就需要使用mysql数据库。

USE mysql;

然后进行选择。

SELECT user,host FROM user;

另一个选项是放置BD.Table

例如 :

SELECT user,host FROM mysql.user;

To see your users, it would be to use the mysql database.

USE mysql;

And then make the select.

SELECT user,host FROM user;

Another option is to put the BD.Table.

For example :

SELECT user,host FROM mysql.user;
甩你一脸翔 2024-08-02 22:22:45

我可以通过此查询获取密码

选择用户名,密码在此处输入代码FROM mysql.user;

但是密码是加密的,加密是什么类型以及如何使用字典攻击解密,这是最好的工具

I can get the password with this query

SELECT username, password enter code hereFROM mysql.user;

But the passwords are encrypted, what type of encryption is that and how to decrypt using dictionary attack which is best tool

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文