如何打印mysql数据库中所有表的所有字段? [英] How do I print all fields for all tables in mysql database?

查看:319
本文介绍了如何打印mysql数据库中所有表的所有字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习一个我不熟悉的mysql数据库的结构.自从我使用mysql已经好几年了.

I'm trying to learn the structure of a mysql database I'm not familiar with. It's been years since I used mysql.

我正在寻找一种打印此数据库中所有表的所有字段的方法.目前,我正在使用

I'm looking for a way to print all the fields for all the tables in this database. At the moment, I'm using

Show Fields from <insert table name>

但是,这又慢又笨拙.有没有更快的方法?

However, this slow and clunky. Is there a faster way?

推荐答案

要查看特定数据库(如mydb)的所有表,请执行以下操作:

To see all tables of a specific database (like mydb), do this:

USE mydb
SHOW TABLES;

要查看mydb.mytable中的所有字段,索引,存储引擎,表选项,分区布局,请执行以下操作:

To see all fields, indexes, storage engine, table options, partition layout in mydb.mytable, do this:

USE mydb
SHOW CREATE TABLE tblname\G

要批量查看所有数据库中的所有表,请使用以下脚本:

To see all tables in all databases in bulk, here is a script:

MYSQL_USER=root
MYSQL_PASS=rootpassword
MYSQL_CONN="-u${MYSQL} -p${MYSQL_PASS}"
MYSQLDUMP_OPTIONS="--routines --triggers --no-data --all-databases"
mysqldump ${MYSQL_CONN} ${MYSQLDUMP_OPTIONS} > MySQLSchema.sql
less MySQLSchema.sql

如果要查看特定的数据库(如mydb),请执行以下操作:

If you want to see a specific database (like mydb), do this:

MYSQL_USER=root
MYSQL_PASS=rootpassword
MYSQL_CONN="-u${MYSQL} -p${MYSQL_PASS}"
DBTOSHOW=mydb
MYSQLDUMP_OPTIONS="--routines --triggers --no-data --databases ${DBTOSHOW}"
mysqldump ${MYSQL_CONN} ${MYSQLDUMP_OPTIONS} > MySQLSchema.sql
less MySQLSchema.sql

这应该是最快的方法,因为如果有很多繁忙的InnoDB表,访问information_schema数据库可能会有点慢.

This should be the quickest way because accessing the information_schema database can be somewhat slow if there are a lot of busy InnoDB tables.

尝试一下!

这篇关于如何打印mysql数据库中所有表的所有字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆