MySQL的show命令

MySQL的show命令可以展示许多信息,也是我们经常使用的命令,本文只是记录下平时常用的show命令。

1、show databases

SHOW DATABASES可以在MySQL服务器主机上列举数据库。您只能看到您拥有某些权限的数据库,除非您拥有全局SHOW DATABASES权限。

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| phpmyadmin |
| test |
+--------------------+
5 rows in set (0.00 sec)

2、show tables

SHOW TABLES列举了给定数据库中的非TEMPORARY表

MariaDB [test]> show tables;
+----------------+
| Tables_in_test |
+----------------+
| user |
+----------------+
1 row in set (0.00 sec)

3、show create database

显示用于创建给定数据库CREATE DATABASE语句

MariaDB [test]> show create database test;
+----------+---------------------------------------------------------------+
| Database | Create Database |
+----------+---------------------------------------------------------------+
| test | CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+---------------------------------------------------------------+
1 row in set (0.00 sec)

4、show create table

显示用于创建给定表CREATE TABLE语句

MariaDB [test]> show create table user;
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| user | CREATE TABLE `user` (
`uid` int(4) NOT NULL AUTO_INCREMENT,
`uname` varchar(10) NOT NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

5、show index

SHOW INDEX会返回表索引信息

MariaDB [test]> show index from  user;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| user | 0 | PRIMARY | 1 | uid | A | 0 | NULL | NULL | | BTREE | | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
1 row in set (0.00 sec)

6、show grants

SHOW GRANTS;
SHOW GRANTS FOR user;
SHOW GRANTS FOR CURRENT_USER;
SHOW GRANTS FOR CURRENT_USER();

用于显示用户权限信息,grant权限语句。

MariaDB [test]> show grants;
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)
转载请注明:6K & 3o » MySQL的show命令

评论:

小美女来了

回复 取消回复

来了!么么哒

回复 取消回复

留下你的评论: