您好,欢迎访问一九零五行业门户网

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_schemaselect * 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清空表的实现方法。
其它类似信息

推荐信息