查询mysql表结构命令

方法1:

desc 表名;

方法2:

show columns from 表名;

方法3:

describe 表名;

方法4:

show create table 表名;
# 此命令是实时反映当前表结构,不是说后期改了表结构了,它就不变的

show create table alert;
CREATE TABLE `alert` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `model` varchar(20) NOT NULL DEFAULT '',
  `stat` int(11) NOT NULL DEFAULT '0',
  `level` int(11) NOT NULL DEFAULT '0',
  `msg` varchar(1000) NOT NULL DEFAULT '',
  `target` varchar(50) NOT NULL DEFAULT '',
  `create_time` datetime NOT NULL,
  `end_time` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

# 我加一个字段
alter table `alert`   
Add column ss int not null default 0;
show create table alert;
CREATE TABLE `alert` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `model` varchar(20) NOT NULL DEFAULT '',
  `stat` int(11) NOT NULL DEFAULT '0',
  `level` int(11) NOT NULL DEFAULT '0',
  `msg` varchar(1000) NOT NULL DEFAULT '',
  `target` varchar(50) NOT NULL DEFAULT '',
  `create_time` datetime NOT NULL,
  `end_time` datetime NOT NULL,
  `ss` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
# 发现多了‘ss’字段的说明了把

还有一种情况是以上方法都不适用的:数据库里的表名是数据库命令的关键字。

desc databases;
# 表名叫‘databases’,错误信息如下,这时候想查表结构,要用方法5
ERROR 1064 (42000): 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 'databases' at line 1

方法5:

select * from information_schema.columns where table_schema = '库名' and table_name = '表名';

方法6:

使用第三方可视化工具,网上很多
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值