(一)SchemaSpy
官方網站:http://schemaspy.sourceforge.net/
該軟體名稱的官方解釋為:Graphical Database Schema Metadata Browser
我的壓縮包(SchemaSpy_5.0.0_工具包):
- SchemaSpy_5.0.0.jar(原版)
- SchemaSpy_5.0.0_mod.jar(我的格式修改版)
- SchemaSpy.mht(協助文檔)
- jtds-1.2.5.jar(最新 強大、開源、純java的 sqlserverJDBC驅動)
- jd-gui.exe (java class 反編譯器)
- __SchemaSpy.cmd (我自己寫的 啟動器,加入 -charset UTF-8 參數)
- Dot.java(修改版的)
(二)常見問題及解決(不斷補充中)
1、中文支援問題
該軟體有個隱藏參數:-charset UTF-8
命令選項中加入該參數即可解決文檔的亂碼問題,但不能解決 Graphviz 圖表的中文問題
2、 軟體所依賴的Graphviz版本問題
該軟體運行必須依賴於Graphviz,主要是依賴其中的Dot命令。
官方的要求是 Graphviz 2.2.1 或 2.4+,否則會出現Dot命令組建圖表失敗的問題。原因是SchemaSpy自作聰明的判斷引擎對預設PNG品質的格式控制,使得內部調用Dot參數 -Tpng命令後添加了品質修飾符":gd"等參數,從而和Graphviz的支援格式不一致。
修改:最簡單的方式是:修改 net.sourceforge.schemaspy.util 下Dot.class 檔案。修改反編譯後的源檔案的 generateDiagram 方法的調用參數:5.0的版本為:
String[] arrayOfString = { getExe(), "-T" + getFormat() + getRenderer(), paramFile1.toString(), "-o" + paramFile2, "-Tcmapx" };
修改為
/* 254 */ String[] arrayOfString = { getExe(), "-Tjpeg", paramFile1.toString(), "-o" + paramFile2, "-Tcmapx" };
注意:該處我根本就不用png格式,而是jpeg格式!!!!
3、和“2”相關的問題,因為該軟體的最新版本5.0看起來也已經很老了,所有很多的代碼和配置不一定適合最新的jdk、db系統,所以,你知道的.......慢慢改唄!
(三)支援的資料庫類型
Type |
Description |
db2 |
IBM DB2 with 'app' Driver |
db2net |
IBM DB2 with 'net' Driver |
udbt4 |
DB2 UDB Type 4 Driver |
db2zos |
DB2 for z/OS |
derby |
Derby (JavaDB) Embedded Server |
derbynet |
Derby (JavaDB) Network Server |
firebird |
Firebird |
hsqldb |
HSQLDB Server |
informix |
Informix |
maxdb |
MaxDB |
mssql |
Microsoft SQL Server |
mssql05 |
Microsoft SQL Server 2005 |
mssql-jtds |
Microsoft SQL Server with jTDS Driver |
mssql05-jtds |
Microsoft SQL Server 2005 with jTDS Driver |
mysql |
MySQL |
ora |
Oracle with OCI8 Driver |
orathin |
Oracle with Thin Driver |
pgsql |
PostgreSQL |
sqlite |
SQLite |
sybase |
Sybase Server with JDBC3 Driver |
sybase2 |
Sybase Server with JDBC2 Driver |
teradata |
Teradata (requires -connprops) |
基本使用文法
Commonly used parameters:
|
Parameter |
Description |
|
-t databaseType |
Type of database (e.g. ora, db2, etc.). Use -dbhelp for a list of built-in types. Defaults to ora . |
* |
-db dbName |
Name of database to connect to |
* |
-u user |
Valid database user id with read access. A user id is required unless -sso is specified. |
|
-s schema |
Database schema. This is optional if it's the same as user or isn't supported by your database. Use -noschema if your database thinks it supports schemas but doesn't (e.g. older versions of Informix). |
|
-p password |
Password associated with that user. Defaults to no password. |
* |
-ooutputDirectory |
Directory to write the generated HTML/graphs to |
|
-dppathToDrivers |
Looks for drivers here before looking in driverPath in [databaseType].properties. The drivers are usually contained in .jar or .zip files and are typically provided by your database vendor. |
|
-hq -lq |
Generate either higher or lower-quality diagrams. Various installations of Graphviz (depending on OS and/or version) will default to generating either higher or lower quality images. That is, some might not have the "lower quality" libraries and others might not have the "higher quality" libraries. Higher quality output takes longer to generate and results in significantly larger image files (which take longer to download / display), but the resultant Entity Relationship diagrams generally look better. |
Parameters marked with '*' are required.
Less commonly used parameters:
-gv pathToGraphviz |
By default SchemaSpy expects the dot executable to be in the PATH environment variable. Use this option to explicitly specify where Graphviz is installed. |
-desc "Schema description" |
Displays the specified textual description on summary pages. If your description includes an equals sign then escape it with a backslash. For example:
-desc "<a href\='http://schemaspy.sourceforge.net'>SchemaSpy</a>" . |
-all |
Evaluate all schemas in a database. Generates a high-level index of the schemas evaluated and allows for traversal of cross-schema foreign key relationships. Use with -schemaSpec "schemaRegularExpression" to narrow-down the schemas to include. |
-schemas"schema1,schema2" |
Evaluate specified schemas. Similar to -all , but explicitly specifies which schema to evaluate without interrogating the database's metadata. Can be used with databases like MySQL where a database isn't composed of multiple schemas. |
-meta metafile |
metafile is either the name of an individual XML file or the directory that contains meta files. If a directory is specified then it is expected to contain files matching the pattern [schema].meta.xml . For databases that don't have schema substitute database for schema. See Providing Additional Metadata for details. |
-connpropspropsfile orkey\=value; |
Specifies additional properties to be used when connecting to the database. Either specify a .properties file (with key=value entries) or specify the entries directly, escaping the ='s with \= and separating each key\=value pair with a ; . |
-i"tableNamesRegex" |
Only include matching tables/views. This is a regular expression that's used to determine which tables/views to include. For example: -i "(.*book.*)|(library.*)" includes only those tables/views with 'book' in their names or that start with 'library'. You might want to use -desc with this option to describe the subset of tables. |
-I"tableNamesRegex" |
Exclude matching tables/views. This regular expression excludes matching tables/views from the analysis. Can be used in conjunction with -i . |
-x"columnNamesRegex" |
Exclude matching columns from relationship analysis to simplify the generated graphs. This is a regular expression that's used to determine which columns to exclude. It must match table name, followed by a dot, followed by column name. For example: -x "(book.isbn)|(borrower.address)" Note that each column name regular expression must be surround by () 's and separated from other column names by a | . Excluded relationships will still show up on detail pages. |
-X"columnNamesRegex" |
Same as -x but excluded relationships will not show up on detail pages. |
-noviews |
Exclude all views. |
-ahic |
Allow HTML In Comments. Any HTML embedded in comments normally gets encoded so that it's rendered as text. This option allows it to be rendered as HTML. |
-norows |
Don't query or display row counts. |
-noimplied |
Don't include implied foreign key relationships in the generated table details. |
-sso |
Single Sign-On. Don't require a user to be specified with -u to simplify configuration when running in a single sign-on environment. |
-pfp |
Prompt For Password. Prompts for the password so it doesn't appear on the command line. |
-nohtml |
Only generate files needed for insertion/deletion of data (e.g. for scripts) and an XML representation of the schema. |
-loglevel |
Specifies how verbose logging of programmatic flow should be. The levels in descending order are:
severe (highest - least detail)
warning (default)
info
config
fine
finer
finest (lowest - most detail)
|
(四)樣本
You run SchemaSpy from the command line:
|
java -jar schemaSpy.jar -t dbType -db dbName [-s schema] -u user [-p password] -o outputDir |
A MySQL example:
java -jar schemaSpy.jar -t mysql -o library -host localhost -db library -u user -p password
|
An MS SQL Server example:
java -jar schemaSpy.jar -t mssql -db library -host localhost -port 1433 -u user -p password -o library
|
我的使用jtds驅動的 MS Sqlserver 執行個體
java -jar schemaSpy_5.0.0_mod.jar -charset UTF-8 -t mssql05-jtds -dp .\jtds-1.2.5.jar -db %db% -host localhost -port 1433 -u sa -p sa -s dbo -o %db%