MySQL "show users" - how to show/list the users in a MySQL database

MySQL users FAQ: How do I show/list MySQL users, i.e., the user accounts in a MySQL database?

To show/list the users in a MySQL database, first log into your MySQL server as an administrative user using the mysql client, then run this MySQL query:

mysql> select * from mysql.user;

However, note that this query shows a large listing of MySQL user information, including user permission information, so as a practical matter you may want to trim down some of the fields to display, something like this:

mysql> select host, user, password from mysql.user;

The next section provides details and background information about this second query.

How to reduce the amount of ‘user’ information shown

You can get a listing of the fields in the mysql.user table by running this MySQL query:

mysql> desc mysql.user;

  

On my current server this shows the following 37 columns of MySQL user information, as shown here:

mysql> desc mysql.user;
+-----------------------+-----------------------------------+------+-----+---------+-------+
| Field                 | Type                              | Null | Key | Default | Extra |
+-----------------------+-----------------------------------+------+-----+---------+-------+
| Host                  | char(60)                          | NO   | PRI |         |       |
| User                  | char(16)                          | NO   | PRI |         |       |
| Password              | char(41)                          | NO   |     |         |       |
| Select_priv           | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Insert_priv           | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Update_priv           | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Delete_priv           | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Create_priv           | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Drop_priv             | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Reload_priv           | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Shutdown_priv         | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Process_priv          | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| File_priv             | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Grant_priv            | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| References_priv       | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Index_priv            | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Alter_priv            | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Show_db_priv          | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Super_priv            | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Create_tmp_table_priv | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Lock_tables_priv      | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Execute_priv          | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Repl_slave_priv       | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Repl_client_priv      | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Create_view_priv      | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Show_view_priv        | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Create_routine_priv   | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Alter_routine_priv    | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| Create_user_priv      | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |
| ssl_type              | enum(‘‘,‘ANY‘,‘X509‘,‘SPECIFIED‘) | NO   |     |         |       |
| ssl_cipher            | blob                              | NO   |     | NULL    |       |
| x509_issuer           | blob                              | NO   |     | NULL    |       |
| x509_subject          | blob                              | NO   |     | NULL    |       |
| max_questions         | int(11) unsigned                  | NO   |     | 0       |       |
| max_updates           | int(11) unsigned                  | NO   |     | 0       |       |
| max_connections       | int(11) unsigned                  | NO   |     | 0       |       |
| max_user_connections  | int(11) unsigned                  | NO   |     | 0       |       |
+-----------------------+-----------------------------------+------+-----+---------+-------+
37 rows in set (0.10 sec)

  

So for most cases where you want to show MySQL user accounts you‘ll probably want to limit your MySQL users‘ query to a few important columns, something like this:

select host, user, password from mysql.user;

  

In summary, if you need to list the users in a MySQL database, I hope this has been helpful.

时间: 2024-08-07 20:53:20

MySQL "show users" - how to show/list the users in a MySQL database的相关文章

Linux Centos 启动mysql ERROR * The server quit without updating PID file (/usr/local/mysql/data/mysql.pid).

做了一些尝试:比如kill -9 进程id  发现根本就杀不死. 查看ERROR.LOG 2015-12-07 18:50:08 29710 [ERROR] /usr/local/mysql/bin/mysqld: unknown variable 'scripts/mysql_install_db --user=mysql' 第一感觉:百度了下.大部分都是说安装的时候有这个问题:感觉场景不太一样:回到原点继续想: scripts/mysql_install_db --user=mysql --

InstallShield在MySQL和Oracle中执行SQL脚本的方法InstallShield在MySQL和Oracle中执行SQL脚本的方法

简述 InstallShield已经内建了对MySQL和Oracle的支持.但是这个功能是通过ODBC实现的,它对SQL脚本的格式要求非常严格,因此已经通过官方客户端测试的脚本在IS中执行时往往就会报错. 一般来说,数据库脚本只保证通过官方客户端测试即可,同时维护一份供IS执行的脚本费时费力.因此,考虑安装程序对两数据库的支持通过官方客户端实现. MySQL   function InstallMySQLComponent(szComponent) NUMBER nResult; STRING

mysql操作命令梳理(5)-执行sql语句查询即mysql状态说明

在日常mysql运维中,经常要查询当前mysql下正在执行的sql语句及其他在跑的mysql相关线程,这就用到mysql processlist这个命令了.mysql> show processlist;            //查询正在执行的sql语句mysql> show full processlist;       //查询正在执行的完整sql语句mysql> kill connection id           //停掉processlist查询出的某个线程,id是对应的

2-14 MySQL初步认识,及CentOS6.8环境,源码方式安装MySQL

什么是数据库: 存放数据的仓库RDBMS-->(Relational Database Management System) 关系型数据库管理系统DBMS--->(Database Managerment System) 数据库管理系统 数据库分类:1. 关系型数据库2. 非关系型数据库常用关系型数据库:Oracle,MySQL,MariaDB,SQL Server,Access,PostgreSQL,DB2,Informix,SybasePostgreSQL 自由的对象-关系数据库服务器(数

mysql start error ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysql.sock’ (2)

When I type mysql, it shows “ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysql.sock’ (2)”. Then I try to start mysql service: $ service mysql start But then I get error “ No directory, logging in with HOME=

长久不用的mysql报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

mac上安装过mysql: 然而,尝试连接时报错: $ mysql -u root -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 尝试去查看mysql.socket文件,发现没有.. $ which mysql /usr/local/bin/mysql 然后试试重启mysql: $ mysql.server start

搞定linux上MySQL编程(一):linux上源码安装MySQL

[版权声明:尊重原创,转载请保留出处:blog.csdn.net/shallnet,文章仅供学习交流,请勿用于商业用途] 1. 首先下载源码包: ftp://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.1/mysql-5.1.72.tar.gz 2. 使用如下命令检查系统中是否已安装mysql: rpm -qa | grep mysql 3.没有安装则解压安装包然后进入该目录: cd mysql 分别依次执行如下操作: ./configure --pr

mac 安装mysql 报错“ERROR 2002 (HY000): Can not connect to local MySQL server through socket '/tmp/mysql.sock' (2)” 解决办法

首先安装 homebrew 再 brew install mysql 之后连接 mysql 无论是登录还是修改初始密码都会报如下的错误 ERROR 2002 (HY000): Can not connect to local MySQL server through socket '/tmp/mysql.sock' (2) 运行如下解决:参考 http://www.thinksaas.cn/group/topic/347978/ unset TMPDIR mysql_install_db --v

MYSQL ERROR 1130: Host is not allowed to connect to this MySQL server

今天安装MYSQL遇到MYSQL ERROR 1130: Host is not allowed to connect to this MySQL server, 试了很多办法都不行 skip-grant-tables 放在my.ini [mysqld] 1.更改任意主机登陆 mysql> use mysql; mysql> update user set host = '%' where user = 'root' and host='localhost'; 2.更新权限 mysql>

.NET程序迁移到Mysql的极简方案——让GGTalk同时支持Sqlserver与mysql全程记录!

园子里的这个GGTalk,咱们前前后后用它移花接木做的IM项目也不下三四个了.初次入手的时候,洋洋代码,多少感觉有些难以把握.不过一来二去,理清了头绪,也就一览无余了.相信跟我们一样想要利用GGTalk的同学大有人在,于是我打算写这样一个<GGTalk源码详解系列>,把自己对GGTalk的梳理分享给大家,让大家更容易上手. 之前有一个企业级的IM项目,我们用GGTalk改造的,但是要求使用Mysql数据库,所以花了一番功夫将GGTalk迁移到的Mysql,功夫不负有心人,总算弄出了个成果.如今