mysql 有没有系统表或者视图?
我希望通过JDBC连接到数据库之后,得到数据库中的所有用户表名、表中的字段名、字段类型,以及表的约束等信息
如果是使用 sql server 或者 oracle,可以通过查询系统表得到这些信息
在 mysql 中应该如何做?
------解决方案--------------------
有个系统信息库:information_schema,里面的表可以供你“做爱做的事情”。
------解决方案--------------------
MYSQL5以上可以访问系统表 INFORMATION_SCHEMA下的各表。
19.1. The INFORMATION_SCHEMA SCHEMATA Table
19.2. The INFORMATION_SCHEMA TABLES Table
19.3. The INFORMATION_SCHEMA COLUMNS Table
19.4. The INFORMATION_SCHEMA STATISTICS Table
19.5. The INFORMATION_SCHEMA USER_PRIVILEGES Table
19.6. The INFORMATION_SCHEMA SCHEMA_PRIVILEGES Table
19.7. The INFORMATION_SCHEMA TABLE_PRIVILEGES Table
19.8. The INFORMATION_SCHEMA COLUMN_PRIVILEGES Table
19.9. The INFORMATION_SCHEMA CHARACTER_SETS Table
19.10. The INFORMATION_SCHEMA COLLATIONS Table
19.11. The INFORMATION_SCHEMA COLLATION_CHARACTER_SET_APPLICABILITY Table
19.12. The INFORMATION_SCHEMA TABLE_CONSTRAINTS Table
19.13. The INFORMATION_SCHEMA KEY_COLUMN_USAGE Table
19.14. The INFORMATION_SCHEMA ROUTINES Table
19.15. The INFORMATION_SCHEMA VIEWS Table
19.16. The INFORMATION_SCHEMA TRIGGERS Table
19.17. The INFORMATION_SCHEMA PLUGINS Table
19.18. The INFORMATION_SCHEMA ENGINES Table
19.19. The INFORMATION_SCHEMA PARTITIONS Table
19.20. The INFORMATION_SCHEMA EVENTS Table
19.21. The INFORMATION_SCHEMA FILES Table
19.22. The INFORMATION_SCHEMA PROCESSLIST Table
19.23. The INFORMATION_SCHEMA REFERENTIAL_CONSTRAINTS Table
19.24. The INFORMATION_SCHEMA GLOBAL_STATUS and SESSION_STATUS Tables
19.25. The INFORMATION_SCHEMA GLOBAL_VARIABLES and SESSION_VARIABLES Tables
19.26. The INFORMATION_SCHEMA PROFILING Table
19.27. Other INFORMATION_SCHEMA Tables
19.28. Extensions to SHOW Statements