如何从 MySQL/phpMyAdmin 中提取数据库模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7991363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pull out schema of db from MySQL/phpMyAdmin?
提问by arun nair
is there some way of pulling out the schema of your mysql databases?
有什么方法可以提取 mysql 数据库的架构吗?
I have lots of db and tables inside these databases, and I use phpmyadmin with WAMP in my local machine.
我在这些数据库中有很多 db 和表,我在本地机器上使用 phpmyadmin 和 WAMP。
I need to pull out the schema, or atleast the database name, table name, columns and their attributes (e.g. INT(2)
) and export it as csv/ excel/ whatever format which finally can be edited in excel.
我需要提取模式,或至少数据库名称、表名称、列及其属性(例如INT(2)
)并将其导出为 csv/excel/任何格式,最终可以在 excel 中进行编辑。
i use:
我用:
server:
服务器:
Apache/2.2.21 (Win64) PHP/5.3.8 MySQL client version: mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $ PHP extension: mysqli Documentation
mysql:
mysql:
Server: localhost (localhost via TCP/IP) Server version: 5.5.16-log Protocol version: 10 User: root@localhost MySQL charset: UTF-8 Unicode (utf8)
thanks!
谢谢!
回答by Salman A
Not sure exactly what you want. You can try one of these methods:
不确定你想要什么。您可以尝试以下方法之一:
1)Use phpMyAdmin's export feature to export the database. PMA allows you to omit the data.
1)使用phpMyAdmin的导出功能导出数据库。PMA 允许您省略数据。
2)You can do the same using mysqldump. This command should export CREATE DATABASE/CREATE TABLE queries:
2)您可以使用mysqldump做同样的事情。此命令应导出 CREATE DATABASE/CREATE TABLE 查询:
mysqldump -hlocalhost -uroot -proot --all-databases --no-data > create-database-and-tables.sql
3)You can pull information from mySQL schema tables. Most mySQL clients (phpMyAdmin, HeidiSQL etc) allow you to export result of queries as CSV. Some useful queries:
3)您可以从 mySQL 模式表中提取信息。大多数 mySQL 客户端(phpMyAdmin、HeidiSQL 等)允许您将查询结果导出为 CSV。一些有用的查询:
/*
* DATABASE, TABLE, TYPE
*/
SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA NOT IN ('information_schema', 'performance_schema', 'mysql')
ORDER BY TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE
/*
* DATABASE, TABLE, COLUMN, TYPE
*/
SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE, IS_NULLABLE /* ETC */
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA NOT IN ('information_schema', 'performance_schema', 'mysql')
ORDER BY TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION
回答by Eugene Yarmash
You can use mysqldump
from the console, e.g.
您可以mysqldump
从控制台使用,例如
mysqldump -h localhost -u user -p -d -r dump.sql db_name
The -d
switch makes mysqldump
to dump the schema only, -r
directs output to a given file. You can also use -X
to write dump in XML format.
该-d
开关mysqldump
仅转储模式,-r
将输出定向到给定文件。您还可以使用-X
XML 格式编写转储。
回答by ?Abdullrahman Hegazy
In the PhpMyAdmin's Export tab for the database, you want:
在数据库的 PhpMyAdmin 的导出选项卡中,您需要:
Check the box : Custom - display all possible options.
Under Format-specific options: section, choose Structure only
选中该框:自定义 - 显示所有可能的选项。
在 Format-specific options: 部分下,选择 Structure only