网站建设资讯

NEWS

网站建设资讯

mysql怎么查表结构,查看MySQL表结构

mysql怎么查看表结构

在我第N次忘记如何查看表结构后,在网上查了一下后,看到有好几种查看表结构的方式,总结一下。

我们一直强调成都网站设计、做网站对于企业的重要性,如果您也觉得重要,那么就需要我们慎重对待,选择一个安全靠谱的网站建设公司,企业网站我们建议是要么不做,要么就做好,让网站能真正成为企业发展过程中的有力推手。专业网站建设公司不一定是大公司,成都创新互联作为专业的网络公司选择我们就是放心。

以student(sid,sname,birthday,sex)的查看为例。

【方式一】:desc student;

语法:desc 表名;---------------------用于查看表整体结构

【方式二】:describe student;

语法:describe 表名;---------------------用于查看表整体结构;

【方式三】:show columns from student;

语法:show columns from 表名;--------------------------用于查看表整体结构;

【方式四】:show create table student;

语法:show create table 表名;--------------------------用于查看表整体结构;

【方式五】:show full fields from student;

语法:show full fields from 表名;--------------------------------- 用于查看表整体结构;

【方式六】:show fields from student;

语法:show fields from 表名;----------------------------用于查看表整体结构;

【方式七】:desc student sname;

语法:desc 表名 成员名;--------------------------------用于查询表中的一部分;

【方式八】:show index from student;

语法:show index from 表名;------------------------------------用于查看表局部结构;这种显示不是很直观,也不是可以完全显示所有信息。

如何读取出mysql中的表结构

Online DDL 工具:pt-osc

对于 MySQL Online DDL 目前主流的有三种工具:

原生 Online DDL;

pt-osc(online-schema-change),

gh-ost

本文主要讲解 pt-online-schema-change 的使用以及三种工具的简单对比。

一、原理及限制

1.1 原理

1. 创建一个与原表结构相同的空表,表名是 _new 后缀;

2. 修改步骤 1 创建的空表的表结构;

3. 在原表上加三个触发器:delete/update/insert,用于 copy 数据过程中,将原表中要执行的语句在新表中执行;

4. 将原表数据以数据块(chunk)的形式 copy 到新表;

5. rename 原表为 old 表,并把新表 rename 为原表名,然后删除旧表;

6. 删除触发器。

mysql怎么查看表结构和注释

MySQL

查看表结构简单命令。

一、简单描述表结构,字段类型desc

tabl_name;

显示表结构,字段类型,主键,是否为空等属性,但不显示外键。

二、查询表中列的注释信息

select

*

from

information_schema.columns

where

table_schema

=

'db'

#表所在数据库

and

table_name

=

'tablename'

;

#你要查的表

三、只查询列名和注释

select

column_name,

column_comment

from

information_schema.columns

where

table_schema

='db'

and

table_name

=

'tablename'

;

四、#查看表的注释

select

table_name,table_comment

from

information_schema.tables

where

table_schema

=

'db'

and

table_name

='tablename'

ps:二~四是在元数据表中查看,我在实际操作中,常常不灵光,不知为什么,有了解的大侠请留印。

五、查看表生成的DDL

show

create

table

table_name;

mysql中查询数据库中表名称和结构的sql语句是什么啊啊

TABLE 语句

具体语法:TABLE table_name [ORDER BY column_name] [LIMIT number [OFFSET number]]

其实从语法上看,可以排序,也可以过滤记录集,不过比较简单,没有 SELECT 那么强大。

示例 1

简单的建一张很小的表 y1,记录数为 10 条。表 t1,插入 10 条记录

mysql-(ytt/3305)-create table t1 (r1 int,r2 int);

Query OK, 0 rows affected (0.02 sec)

mysql-(ytt/3305)-insert into t1

with recursive aa(a,b) as (

select 1,1

union all

select a+1,ceil(rand()*20) from aa where a 10

) select * from aa;

Query OK, 10 rows affected (0.00 sec)

Records: 10  Duplicates: 0  Warnings: 0

简单全表扫描mysql-(ytt/3305)-select * from t1;+------+------+| r1   | r2   |+------+------+|    1 |    1 ||    2 |    9 ||    3 |    9 ||    4 |   17 ||    5 |   17 ||    6 |   16 ||    7 |    6 ||    8 |    1 ||    9 |   10 ||   10 |    3 |+------+------+10 rows in set (0.00 sec)

TABLE 结果mysql-(ytt/3305)-table t1;+------+------+| r1   | r2   |+------+------+|    1 |    1 ||    2 |    9 ||    3 |    9 ||    4 |   17 ||    5 |   17 ||    6 |   16 ||    7 |    6 ||    8 |    1 ||    9 |   10 ||   10 |    3 |+------+------+10 rows in set (0.00 sec)

看下 table 的执行计划mysql-(ytt/3305)-explain table t1 order by r1 limit 2\G*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: t1   partitions: NULL         type: ALLpossible_keys: NULL          key: NULL      key_len: NULL          ref: NULL         rows: 10     filtered: 100.00        Extra: Using filesort1 row in set, 1 warning (0.00 sec)

其实可以看到 TABLE 内部被 MySQL 转换为 SELECT 了。mysql-(ytt/3305)-show warnings\G*************************** 1. row ***************************  Level: Note   Code: 1003Message: /* select#1 */ select `ytt`.`t1`.`r1` AS `r1`,`ytt`.`t1`.`r2` AS `r2` from `ytt`.`t1` order by `ytt`.`t1`.`r1` limit 21 row in set (0.00 sec)

那其实从上面简单的例子可以看到 TABLE 在内部被转成了普通的 SELECT 来处理。示例 2应用于子查询里的子表。这里要注意,内表的字段数量必须和外表过滤的字段数量一致。克隆表 t1 结构mysql-(ytt/3305)-create table t2 like t1;Query OK, 0 rows affected (0.02 sec)

克隆表 t1 数据mysql-(ytt/3305)-insert into t2 table t1;Query OK, 10 rows affected (0.00 sec)Records: 10  Duplicates: 0  Warnings: 0

table t1 被当做内表,表 t1 有两个字段,必须同时满足 t2 检索时过滤的字段也是两个。mysql-(ytt/3305)-select * from t2 where (r1,r2) in (table t1);+------+------+| r1   | r2   |+------+------+|    1 |    1 ||    2 |    9 ||    3 |    9 ||    4 |   17 ||    5 |   17 ||    6 |   16 ||    7 |    6 ||    8 |    1 ||    9 |   10 ||   10 |    3 |+------+------+10 rows in set (0.00 sec)

注意:这里如果过滤的字段数量和子表数量不一致,则会报错。

mysql如何查看表结构

Online DDL 工具:pt-osc

对于 MySQL Online DDL 目前主流的有三种工具:

原生 Online DDL;

pt-osc(online-schema-change),

gh-ost

本文主要讲解 pt-online-schema-change 的使用以及三种工具的简单对比。

一、原理及限制

1.1 原理

1. 创建一个与原表结构相同的空表,表名是 _new 后缀;

2. 修改步骤 1 创建的空表的表结构;

3. 在原表上加三个触发器:delete/update/insert,用于 copy 数据过程中,将原表中要执行的语句在新表中执行;

4. 将原表数据以数据块(chunk)的形式 copy 到新表;

5. rename 原表为 old 表,并把新表 rename 为原表名,然后删除旧表;

6. 删除触发器。

mysql数据库怎么查看表结构

登陆mysql

命令:

mysql -uroot -p

此处以mysql数据库的func表为例

查看表结构的方法1

命令:

desc func;

方法2

命令:

describe func;

方法3

命令:

show columns from func;

方法3

命令:

explain func;

方法3

使用mysql的工具mysqlshow.exe

mysql 数据库 表


网站栏目:mysql怎么查表结构,查看MySQL表结构
网页URL:http://cdweb.net/article/dscdocs.html