mysql查看表结构报错_MySQL查看表和清空表的常用命令总结

查看mysql数据库表进入mysql command line client下

查看当前使用的数据库:

mysql>select database();

mysql>status;

mysql>show tables;

mysql>show databases;//可以查看有哪些数据库,返回数据库名(databasename)

mysql>use databasename; //更换当前使用的数据库

mysql>show tables; //返回当前数据库下的所有表的名称

或者也可以直接用以下命令

mysql>show tables from databasename;//databasename可以用show databases得来

mysql查看表结构命令,如下:

desc 表名;

show columns from 表名;

或者

describe 表名;

show create table 表名;

或者

use information_schema

select * from columns where table_name='表名';

查看警告:

rows matched: 1 changed: 0 warnings: 1

mysql> show warnings;

+---------+------+-------------------------------------------+

| level | code | message |

+---------+------+-------------------------------------------+

| warning | 1265 | data truncated for column 'name' at row 3 |

+---------+------+-------------------------------------------+

1 row in set

以上就是查看mysql数据库表的命令介绍。

mysql清空表mysql清空表是很重要的操作,也是最常见的操作之一,下面就为您详细介绍mysql清空表的实现方法,希望能够对您有所帮助。

方法1:重建库和表

用mysqldump --no-data把建表sql导出来,然后drop database再create database,执行一下导出的sql文件,把表建上;

方法2:生成清空所有表的sql

mysql -n -s information_schema -e "select concat('truncate table ',table_name,';') from tables where table_schema='eab12'"

输出结果如下:

truncate table authgroupbindings;

truncate table authgroups;

truncate table authusers;

truncate table corpbadcustominfo;

truncate table corpsmsblacklisyinfo;

truncate table corpsmsfilterinfo;

truncate table corpsmsinfo;

truncate table eabasereginfos;

truncate table eacorpblob;

truncate table eacorpinfo;

....

....

这样就更完善了:

mysql -n -s information_schema -e "select concat('truncate table ',table_name,';') from tables where table_schema='eab12'" | mysql eab12

即清空eab12中所有的表。

但是如果有外键的话,很可能会报错。因此还需要加个-f

mysql -n -s information_schema -e "select concat('truncate table ',table_name,';') from tables where table_schema='eab12'" | mysql -f eab12

多执行几次,直到不报错。

以上就是mysql清空表的实现方法。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值