且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何打印mysql数据库中所有表的所有字段?

更新时间:2023-11-26 23:02:10

要查看特定数据库(如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.

尝试一下!