MYSQL SHOW 用法

1、SHOW CHARACTER SET 显示所有可用的字符集

mysql> SHOW CHARACTER SET LIKE ‘utf8‘;
+---------+---------------+-------------------+--------+
| Charset | Description | Default collation | Maxlen |
+---------+---------------+-------------------+--------+
| utf8 | UTF-8 Unicode | utf8_general_ci | 3 |
+---------+---------------+-------------------+--------+
1 row in set (0.00 sec)

2、SHOW COLLATION 显示所有的校对规则

mysql> SHOW CHARACTER SET LIKE ‘utf8‘;
+---------+---------------+-------------------+--------+
| Charset | Description | Default collation | Maxlen |
+---------+---------------+-------------------+--------+
| utf8 | UTF-8 Unicode | utf8_general_ci | 3 |
+---------+---------------+-------------------+--------+
1 row in set (0.00 sec)

3、SHOW COLUMNS 显示在一个给定表中的各列的信息(等同于DESC)

mysql> SHOW COLUMNS FROM zjf.a1;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | NO | | NULL | |
+-------+---------+------+-----+---------+-------+
1 row in set (0.15 sec)

4、SHOW CREATE TABLE 显示用于创建给定表的CREATE TABLE语句

mysql> SHOW CREATE TABLE zjf.a1;
+-------+----------------------------------------------------------------------------------+
| Table | Create Table |
+-------+----------------------------------------------------------------------------------+
| a1 | CREATE TABLE `a1` (
`id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+----------------------------------------------------------------------------------+
1 row in set (0.00 sec)

5、SHOW OPEN TABLES 显示数据库中正在打开的表

mysql> SHOW OPEN TABLES FROM zjf;
+----------+-------+--------+-------------+
| Database | Table | In_use | Name_locked |
+----------+-------+--------+-------------+
| zjf | a1 | 0 | 0 |
+----------+-------+--------+-------------+
1 row in set (0.00 sec)

6、SHOW TABLES 显示数据库的所有表

mysql> USE zjf;
Database changed
mysql> SHOW TABLES;
+---------------+
| Tables_in_zjf |
+---------------+
| a1 |
+---------------+
1 row in set (0.00 sec)

7、SHOW TABLE STATUS 性质与SHOW TABLE类似,不过,可以提供每个表的大量信息

mysql> SHOW TABLE STATUS FROM zjf WHERE Name=‘a1‘;
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------+
| a1 | InnoDB | 10 | Dynamic | 0 | 0 | 16384 | 0 | 0 | 0 | NULL | 2016-02-17 11:24:19 | NULL | NULL | utf8_general_ci | NULL | | |
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------+
1 row in set (0.00 sec)

8、SHOW DATABASES 在MySQL服务器主机上列举数据库

mysql> SHOW DATABASES LIKE ‘zjf‘;
+----------------+
| Database (zjf) |
+----------------+
| zjf |
+----------------+
1 row in set (0.00 sec)

9、SHOW ENGINE 显示存储引擎的日志或状态信息

mysql> SHOW ENGINE innodb status \G
*************************** 1. row ***************************
Type: InnoDB
Name:
Status:
=====================================
2016-02-17 13:28:24 0x7f9eeea16700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 24 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 4 srv_active, 0 srv_shutdown, 7149 srv_idle
srv_master_thread log flush and writes: 7153
...

10、SHOW ENGINES 显示存储引擎的状态信息

mysql> SHOW ENGINES;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| CSV | YES | CSV storage engine | NO | NO | NO |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)

11、SHOW ERRORS 本语句与SHOW WARNINGS接近,不过该语句只显示错误,不同时显示错误、警告和注意。

mysql> SHOW ERRORS;
+-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Error | 1064 | You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘LIKE ‘DEFAULT‘‘ at line 1 |
+-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SHOW COUNT(*) ERRORS;
+-----------------------+
| @@session.error_count |
+-----------------------+
| 1 |
+-----------------------+
1 row in set (0.00 sec)

12、SHOW WARNINGS显示由上一个生成消息的语句导致的错误、警告和注意消息。

mysql> SHOW WARNINGS;
Empty set (0.08 sec)

mysql> SHOW COUNT(*) WARNINGS;
+-------------------------+
| @@session.warning_count |
+-------------------------+
| 0 |
+-------------------------+
1 row in set (0.00 sec)

13、SHOW VARIABLES显示了部门MySQL系统变量的值

mysql> SHOW VARIABLES LIKE ‘version‘;
+---------------+--------+
| Variable_name | Value |
+---------------+--------+
| version | 5.7.11 |
+---------------+--------+
1 row in set (0.00 sec)

14、 SHOW GRANTS 用户账户复制权限时必须发布的GRANT语句

mysql> SHOW GRANTS;
+---------------------------------------------------------------------+
| Grants for [email protected] |
+---------------------------------------------------------------------+
| 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)

15、SHOW INDEX 返回表索引信息

mysql> SHOW INDEX FROM mysql.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 | Host | A | NULL | NULL | NULL | | BTREE | | |
| user | 0 | PRIMARY | 2 | User | A | 2 | NULL | NULL | | BTREE | | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.04 sec)

16、SHOW PRIVILEGES 显示MySQL服务器支持的系统权限清单

mysql> show privileges;
+-------------------------+---------------------------------------+-------------------------------------------------------+
| Privilege | Context | Comment |
+-------------------------+---------------------------------------+-------------------------------------------------------+
| Alter | Tables | To alter the table |
| Alter routine | Functions,Procedures | To alter or drop stored functions/procedures |
| Create | Databases,Tables,Indexes | To create new databases and tables |
| Create routine | Databases | To use CREATE FUNCTION/PROCEDURE |
| Create temporary tables | Databases | To use CREATE TEMPORARY TABLE |
| Create view | Tables | To create new views |
| Create user | Server Admin | To create new users |
...

17、SHOW PROCESSLIST显示哪些线程正在运行(高端)

mysql> show processlist;
+----+------+-----------+------+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+----------+------------------+
| 3 | root | localhost | NULL | Query | 0 | starting | show processlist |
+----+------+-----------+------+---------+------+----------+------------------+
1 row in set (0.00 sec)

18、SHOW STATUS提供服务器状态信息

mysql> SHOW STATUS LIKE ‘Binlog%‘;
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| Binlog_cache_disk_use | 0 |
| Binlog_cache_use | 0 |
| Binlog_stmt_cache_disk_use | 0 |
| Binlog_stmt_cache_use | 0 |
+----------------------------+-------+
4 rows in set (0.05 sec)

19、SHOW TRIGGERS 列出了目前被MySQL服务器定义的触发程序

mysql> SHOW TRIGGERS LIKE ‘acc%‘;
+---------+--------+---------+-------------------------------+--------+---------+
| Trigger | Event | Table | Statement | Timing | Created |
+---------+--------+---------+-------------------------------+--------+---------+
| ins_sum | INSERT | account | SET @sum = @sum + NEW.amount | BEFORE | NULL |
+---------+--------+---------+-------------------------------+--------+---------+

参考文档:

MySQL 5.1手册

时间: 2024-11-05 15:17:38

MYSQL SHOW 用法的相关文章

mysql学习之二:mysql基本用法

安装完mysql后我们可以进行sql语句的操作: 我们可以使用以下命令连接到MySQL服务: mysql -h localhost -u root -p -h参数指定要连接的MySQL服务器地址 -u参数指定连接所使用的用户 -p参数指定使用密码验证登陆 MySQL服务绝大多数功能使用SQL语言进行管理. SQL语言一般约定俗成使用大写,但是语言本身不限制大小写.几乎所有SQL语句都必须以";"结尾. 列出所有数据库: SHOW DATABASES; 创建一个数据库(linuxcast

MySQL:ONDUPLICATEKEYUPDATE用法

如果在INSERT语句末尾指定了ON DUPLICATE KEY UPDATE,并且插入行后会导致在一个UNIQUE索引或PRIMARY KEY中出现重复值,则执行旧行UPDATE:如果不会导致唯一值列重复的问题,则插入新行.例如,如果列a被定义为UNIQUE,并且包含值1,则以下 两个语句具有相同的效果: 原本需要执行3条SQL语句,如下: 代码如下: IF (SELECT * FROM t_table WHERE id=1001') { UPDATE t_table SET cnt=cnt+

Mysql基本用法-02

left join #左连接又叫外连接 left join 返回左表中所有记录和右表中连接字段相等的记录  test_user表 phpcvs表 SQL: select * from test_user left join phpcvs on test_user.id=phpcvs.id 执行结果如下图: right join #右连接又叫外连接 right join返回右表中所有记录和左表中连接字段相等的记录  SQL: select * from test_user right join p

mysql基本用法

最近项目使用mysql数据库,以前没接触过.所以找了些资料学习. 目前通过navicat for mysql工具进行mysql数据基本操作. 1.安装navicat for mysql后,建立连接. 2.导入需要创建的sql语句.通过选中库名称右键运行sql文件,加载需要导入的sql语句. 3.增加其中数据,注意增加的字段如果增加提示1306错误,需要修改字段的符号位utf8后即可增加 4.如果远程连接mysql服务器,需要在远程服务器mysql中对客户端访问进行授权语句 GRANT ALL P

mysql FIND_IN_SET 用法

mysql 中 FIND_IN_SET  是判断某个字符串是否在带逗号的字符串中 例如 SELECT t.group_id, COUNT(group_id) tsum FROM (SELECT group_id FROM xx WHERE FIND_IN_SET(openid,'qqqwqnfocFq5IL2sXB2Qu0I,oarwerrr-2KRah_TklJEomljhlKg,oaSiouEgtr5t5utLFU8-evmkn5BwQ3_c') AND user_uuid = 'xxxxx

知识点:Mysql 基本用法之函数

函数 MySQL中提供了许多内置函数 例如: sql 内置函数: 一.数学函数 ROUND(x,y) 返回参数x的四舍五入的有y位小数的值 RAND() 返回0到1内的随机值,可以通过提供一个参数(种子)使RAND()随机数生成器生成一个指定的值. 二.聚合函数(常用于GROUP BY从句的SELECT查询中) AVG(col)返回指定列的平均值 COUNT(col)返回指定列中非NULL值的个数 MIN(col)返回指定列的最小值 MAX(col)返回指定列的最大值 SUM(col)返回指定列

知识点:Mysql 基本用法之存储过程

存储过程 一. 介绍 存储过程包含了一系列可执行的sql语句,存储过程存放于MySQL中,通过调用它的名字可以执行其内部的一堆sql 使用存储过程的优点: 用于替代程序写的SQL语句,实现程序与sql解耦 基于网络传输,传别名的数据量小,而直接传sql数据量大 使用存储过程的缺点: 程序员扩展功能不方便 补充:程序与数据库结合使用的三种方式 方式一: MySQL:存储过程 程序:调用存储过程 方式二: MySQL: 程序:纯SQL语句 方式三: MySQL: 程序:类和对象,即ORM(本质还是纯

知识点:Mysql 基本用法之事务

事务 事务用于将某些操作的多个SQL作为原子性操作,一旦有某一个出现错误,即可回滚到原来的状态,从而保证数据库数据完整性. 事务实例: create table user( id int primary key auto_increment, name char(32), balance int ); insert into user(name,balance) values ('大木木',1000), ('二木木',1000), ('三木木',1000); #原子操作 start transa

mysql高级用法(函数)

mysql 高级用法 # CONCAT 函数用于将两个字符串连接为一个字符串 SELECT CONCAT(businfo_name,businfo_creditCode) FROM tb_businfo LIMIT 0,10; # CONCAT_WS 函数用于将两个字符串连接为一个字符串,第一个参数是其它参数的分隔符 # mysql CONCAT_WS()不会忽略任何空字符串. (然而会忽略所有的 NULL) SELECT CONCAT_WS(',',businfo_name,businfo_c

Python3中使用Mysql的用法。

一.Python2中一般使用MySqldb来调用Mysql,但是在Python3中不支持该包,使用pymysql来代替了,用法一模一样. 二.安装: pip install pymysql 三.例子: #coding utf-8 import pymysql try: conn = pymysql.connect(host='localhost',user="root",password='123456',database='datarepair',port=3306,charset=