MySQL Workbench - How to synchronize the EER Diagram - mysql

I am creating a visual representation of my existing database with MySQL Workbench and I am able to synchronize the models with the "Database -> Synchronize Model..." menu. However, every time I synchronize (update) my model, I have to recreate the EER Diagram and rearrange all the tables. Is there a way to update or synchronize the EER Diagram as well? Thanks.

Database > Synchronize Model...
Choose Stored Connection
Select the Schemata
Choose which to update: Model or Source (in your case, point arrows to Model)

Are you by any chance using a MySQL DB engine that doesn't support foreign keys (e.g. MyISAM?)? Hence, the relations between the tables is not saved on the MySQL server and get lost during synchronization to the workbench.
But I realize this is only the 'why' of your question. I cannot provide an answer that would preserve your arrangement without using an engine that supports foreign keys, e.g. InnoDB.

I was having a variant of this problem--somehow when I would update the model from the database, one of my tables and its corresponding updatable view wouldn't update.
I believe what was happening is that the model was actually updating, but not the diagram. I didn't really make the distinction at first.
Anyway here's how to get the refresh on the E/R diagram:
Delete the nonupdating object(s) from the diagram. (Just right click and choose "Delete".)
Find the objects in the catalog view in the left sidebar.
Drag them back onto the diagram.
Now they should reflect the model (which should reflect the DB if you followed the accepted answer above.)

When I have more than 3 tables to sync, with changes on relations, I changes arrow direction (model <- source), I check "Skip DB changes and update model only" and Execute...
The "Progress of Model and Database Synchronization" window hang with "Apply changes to Model" highlighted. No processor working, nothing move...
I click the X of the window and redo the process again. Clicking the DB, ignore (all), and selecting less tables to update.
v.5.2.44 ce rev 9933
EDIT: Version 5.2.47 correct this bug !!! YĆ© !

Related

Only updates from MySQL Workbench diagram/Model?

After creating an initial schema, is there a way to alter that schema and export only the alterations when working w/ Workbench Models?
Use case being -- there's a live database running the old schema and no data is to be lost, but new updates need to happen.
As suggested by Mike Lischke - my comments reposted as answer - but only so it can be marked as such when searching SO not for the points.
If you are only adding columns and tables - then the "Synchronize Model" or "Synchronise with Any Source" commands under the Database menu in MySQL Workbench (when you have the model open) should do the job with no data loss. You can step through & review the final SQL commands prior to running them if you like. Try it out on a test schema first - see what happens. I have done this on several occasions on live databases without problems but I would recommend creating a backup of your live database before hand - better safe than sorry.
If there are data conversions then MySQL will do it'd best to handle that - but it may have impact on your queries & any processing on the data. Anything complicated I would do in several stages - first add temporary columns, then perform the required conversions into the temporary columns then drop the original columns & rename the temporary columns.

Adding new table to ER Diagram

I created database and ER Diagram. Then I added new table to exsisting database. Now I would like have this table in my ER Diagram. How can I do it? Have I to create new Diagram? Of course I can use the table tool on the vertical toolbar, but if I have new table I suppose that is better way to get this table in Diagram.
First, always upgrade to the latest MySQL Workbench version (at the time being 6.0.9 with 6.1 around the corner).
I assume you created your EER diagram from the database via reverse engineering. Any time you want to update either the model or the database (schema) run the synchronization in MySQL Workbench. Open a model and go to Database -> Synchronize Model.... This is a two-way tool (model to schema and schema to model), but you can manually define the direction (or to ignore a change). Once you have synchronized your changed schema the new table will appear in the catalog tree where you can drag it to a diagram.
There should be a pane on the left titled Catalog Tree in the tab for your existing EER diagram.
You can drag and drop your new table onto the existing diagram. If the table isn't listed, do a refresh on the dbname in the tree view.

What Inserts tab does in MySQL Workbench EER Diagram Table Editing?

I needed to insert some initial (default) data into a new database and I found this Inserts tab on MySQL Workbench EER Diagram table editing form
My assumption was that I can use it to insert initial (default) data that will get propagated to the database during synchronization (not sure how it will get merged with any existing data in the database though...). I added couple rows and synced model with an empty database, but no data was inserted.
So, my question is what this Inserts tab is for on the Table Editing screen?
I use MySQL Workbench 6.
P.S. If somebody can also point to an easy way to insert initial (default) data (except simply running a SQL script) I will appreciate it.
Thank you.
The data added on the INSERTs page is indeed thought to be like an initial set of (test)data. It doesn't consider existing data however. I think it is also only used if you do forward engineering, not on synchronization.
Other ways of inserting data always involve an SQL script, that's what the (text) API is about for SQL servers. But you can add scripts to your model too (see the overview page). They are not run automatically, however.

How to make MySQL Workbench forget I renamed a table?

Early on in my design phase I made the mistake of renaming a table and then creating a new table with the old name. For some reason, MySQL Workbench decided to remember this fact very well. Now every time I try to synchronize with a database, MySQL Workbench wants to rename the (new) table back to its old name.
I did this:
Rename my_table => my_new_table
Create new table called 'my_table'
And now MySQL Workbench insists this would be the right way to proceed:
Rename my_new_table => my_table
Drop my_new_table
That's clearly a bug in its own right, but how is MySQL Workbench keeping track of what it has done with the tables of a random DB? Is there some metadata somewhere I can clear to make MySQL Workbench to believe that this change has already taken place and need not to be repeated? Clearly Workbench is doing more than just a diff between the model and the existing database...
(I realize I could just ignore the the particular step in synchronization process, but I don't want to do it every time I synchronize and of course any changes to these two particular tables would be never carried out...)
Managed to work around the issue by running synchronization once with "skip DB changes and update model only". Unclear whether there are bits of the schemata out of sync or not, but at least new changes now carry over.
Renaming an object and creating a new one with the same name is a special case which makes it quite difficult for the synchronization process. The reason is that Workbench uses the names to find objects (as there is no other identification mechanism like UUIDs or similar). So extra steps are done to find such a rename situation. Workbench explicitly keeps the old name to have a way to find what to sync how.

How to create E-R diagram in mysql

I am using MySQL. There are 28 tables in my database. I've tried to use MySQL Workbench to create E-R diagram. As there are 28 tables, everything is messed up in diagram using MySQL Workbench. Is there any way to create E-R Diagram which shows all relations properly between 28 tables??
Thanks
The only free app I've been able to find that generates decent graphics (not beautiful but quite clear) is SchemaSpy. It's a command line Java program that generates quite comprehensive HTML documentation for any DBMS.
To Create ER Diagram in MySQL follow these steps:
1.First install MySQL Workbench in your computer
Click File->Import->Reverse Engineer MySQL Create Script.
Click Browse and select your SQL create script.
Make Sure "Place Imported Objects on a diagram" is checked.
Click Execute Button.
Click Model->Add Diagram.
Open Catalog Tree and select/drag your tables on your ERR diagram.
ERWin is another good tool. Allowing you to generate erd from sql code and sql code from er diagrams. Its a Drag and Drop utility.
SQL yog is one of the best tool which generate ERD and represents the relationship between different tables.
It is also drag and drop utility and provide complete access to your mysql database.
Open the MySQL Workbench and then go to Database -> Reverse Engineer (in this wizard you have 7 steps to generate the ER Diagram)
1-Connection Options:
For Stored Connection :( Select local instance )
For Password: Click on the Store in Vault.. and then enter your password
Then click on the next.
2-Connect to DBMS:
Click on the next (In this step you do not need to do anything)
3-Select Schemas
Here, select your desire Schema in order to generate an ER Diagram
4-Retrieves Objects
Click on the next (In this step you do not need to do anything)
5-Select Objects
In this step, you can click on the Show Filter to exclude some table if you like
Here, I exclude the emailAddresses table in order not to show that in the ER Diagram
6-Reverses Engineers
Click on the next (In this step you do not need to do anything)
7-Results
Click on the finish to see the Diagram