CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources...

21
August 25, 2015 Sam Siewert CS317 File and Database Systems Using MySQL Workbench [PRClab] http://dev.mysql.com/downloads/workbench

Transcript of CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources...

Page 1: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

August 25, 2015 Sam Siewert

CS317 File and Database Systems

Using MySQL Workbench [PRClab]

http://dev.mysql.com/downloads/workbench

Page 2: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Resources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward Engineer – From EER Entered into mysql-workbench to PRClab DBMS – Creates Tables, Keys, Views, etc. from Design

Reverse Engineer – From DBMS to EER in myql-workbench – Useful to Understand and Improve existing DBMS

Workbench Tutorial - https://www.youtube.com/watch?v=X_umYKqKaF0

Sam Siewert 2

Page 3: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Methods to Connect to MySQL MySQL-Workbench must CONNECT to MySQL Server to use FORWARD/REVERSE Engineering Option 1 – Run mysql-workbench on PRClab with Display set back to your PC and use LOCAL connection – http://mercury.pr.erau.edu/~siewerts/cs317/documents/Basic-

PRClab-Account-Verification-for-CS317.pdf – Must run Xming and must set X11 Display – Launch mysql-workbench on PRClab (/usr/bin/mysql-workbench)

Option 2 – Run mysql-workbench on your PC with SSH Tunnel to PRClab MySQL Server Sam Siewert 3

Page 4: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Option-1 Setup Run mysql-workbench on PRClab with Display set back to your PC Enter Localhost connection for your MySQL account

Sam Siewert 4

Page 5: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Option-1 Example

Sam Siewert 5

Start mysql-workbench On PRClab Displayed back to PC

MySQL PRClab Password

Page 6: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Option-2 Setup Generate SSH Keys on PRClab for your account – In directory .ssh Copy and paste id_rsa contents into file on your

PC

– Start up mysql-workbench on your PC and set up SSH Tunnel using id_rsa private key on your PC

Sam Siewert 6

Truncated for security purposes

Page 7: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

SSH Tunnel Configuration

Sam Siewert 7

SSH Tunnel

PRClab Account

PRClab id_rsa

PRClab MySQL username

Page 8: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Option-2 Example Enter PRClab Password Enter MySQL PRClab Server Password Now workbench is connected to PRClab MySQL Server over Tunnel

Sam Siewert 8

Page 9: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

USING MYSQL-WORBENCH Example Forward and Reverse Engineering

Sam Siewert 9

Page 10: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

A few Tips – for FORWARD Use both FORWARD and REVERSE Engineer For FORWARD, make MWB Design file Name Same as your DBMS Target – E.g. siewertsDHV1 – Make sure you

have been Granted Privileges for this DBMS to DROP, and for all DDL Commands

Rename if needed as shown

Sam Siewert 10

Right Click Here – Change all Names and Save as Filename that MATCHES

Page 11: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Going from Paper Design to Schemas Relational Models, ER, and EER on Paper are Helpful, but How Do We Transition to a Schema we Can Test? Workbench can be Downloaded and Installed on Windows, Max OS-X, Linux - http://dev.mysql.com/downloads/workbench Enter Design as an EER using Graphical Workbench

Sam Siewert 11

Generate SQL DDL Schema When Ready…

Page 12: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Reverse Engineer Existing Schema to EER DreamHome v. 1.0 – 6 Tables, Related by Foreign Keys Not Taking Advantage of EER, but Can Update Model and Export, Re-Import Data to Improve

Sam Siewert 12

Page 13: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Sakila EER Model

Sam Siewert 13

Tables, Views, SQL/PSM Routines, Triggers in EER

Page 14: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Sakila Example Tables, Views, PSM Routines, Triggers Models Relations Between Entities [Tables] and Includes Operations [Routines] More Sophisticated Design and Schema that Matches

Sam Siewert 14

Page 15: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Reverse Engineer Differences The Forward/Reverse Engineering is Not Perfect, but Not Bad SQL Generation from Pictures, Picture Generation from SQL Much like at GUI Code Generator Issue is Sync Between Design and SQL Sam Siewert 15

Page 16: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Recall DreamHome v. 2.0 ER Design Entities, Attributes, Keys, 1:1, 1:*, *:1 Relations – P. 359 Features PK and FK Attributes

Sam Siewert 16

Page 17: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Improvements to DreamHome v. 1.0 Connections 1:n Made Via PKs Note InnoDB Physical Engine Required for FKs Improve Model and Schema

Sam Siewert 17

FKs Require InnoDB, MyISAM default [Many options – MEMORY, FEDERATED, ScaleDB…]

Page 18: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

DreamHome v. 1.0 EER See if We Can Improve PK, FK and Normalization

Sam Siewert 18

Page 19: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Check Schema and Add Test Data Review Schema

Sam Siewert 19

Page 20: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

DreamHome v. 2.0 Global EER

Sam Siewert 20

Page 21: CS317 File and Database Systemsmercury.pr.erau.edu/.../Linux/Lecture-MySQL-Workbench.pdfResources for MySQL-Workbench Examine Use of MySQL Workbench to Go Between EER and Schemas Forward

Equivalent Using DH v. 1.0 Adapted

Sam Siewert 21