PowerDesigner 连接MySQL数据库详细步骤
简介
有的时候我们想把数据表结构可视化,想知道表中有哪些字段,表与表之间的关联关系,这个时候我们可以使用PowerDesigner工具,将表转化为可视化模型。
工具
- 1、PowerDesigner 16.5
- 2、mysql-connector-odbc-8.0.15-win32
准备工作
- 1 安装PowerDesigner 16.5
- 2 安装mysql-connector-odbc-8.0.15-win32 。去 官网下载mysql-connector-odbc ,这里不推荐使用64位,有可能
PowerDesigner找不到驱动,直接安装32位即可。
连接MySQL数据库详细步骤
一、新建一个 Physical Data ,选择自己要连接的数据库
在PowerDesigner菜单栏中,依次点击“File ->New Model->Physical Data” 点击OK
二、连接数据源:
依次点击“File ->Reverse Enginner->Database…” 显示如下页面,点击确定
点击红框,弹出一下画面,
点击configure…
点击创建新的数据源,选择用户数据源
然后下一步,找到MYSQL驱动,选择MYSQL ODBC 8.0 Unicode Driver ,点击完成。
填写名称以及备注,连接的数据库IP地址,账号密码以及数据库
这里基本上大功告成!但是发现展示的全部是字段名称,我们想展示注释的话还需要一步操作。
三、PowerDesigner设计Name和注释相互替换
Name是名称(字段描述),Code是字段名称,Comment是注释名称,ER图中显示的是Name。一般设计时,Name跟comment都设计成描述,
而设计时候常把comment写成中文,name保留跟code一致,保存完毕后,可以把comment替换到name上。当然也可以用name替换comment。具体方法如下:
将以下脚本执行: “tools ->execute commands->edit/run script”
- 1.将comment覆盖name
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl ' the current model
' get the current active model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no current Model "
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
MsgBox "The current model is not an Physical Data model. "
Else
ProcessFolder mdl
End If
Private sub ProcessFolder(folder)
On Error Resume Next
Dim Tab 'running table
for each Tab in folder.tables
if not tab.isShortcut then
tab.name = tab.comment
Dim col ' running column
for each col in tab.columns
if col.comment="" then
else
col.name= col.comment
end if
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.name = view.comment
end if
next
' go into the sub-packages
Dim f ' running folder
For Each f In folder.Packages
if not f.IsShortcut then
ProcessFolder f
end if
Next
end sub
- 2.将name覆盖comment
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl ' the current model
' get the current active model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no current Model "
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
MsgBox "The current model is not an Physical Data model. "
Else
ProcessFolder mdl
End If
' This routine copy name into comment for each table, each column and each view
' of the current folder
Private sub ProcessFolder(folder)
Dim Tab 'running table
for each Tab in folder.tables
if not tab.isShortcut then
tab.comment = tab.name
Dim col ' running column
for each col in tab.columns
col.comment= col.name
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.comment = view.name
end if
next
' go into the sub-packages
Dim f ' running folder
For Each f In folder.Packages
if not f.IsShortcut then
ProcessFolder f
end if
Next
end sub
转换结果如下:
参考文献
https://blog.csdn.net/superhoy/article/details/13018717?locationNum=13