MySQL Workbench not showing schemas in Models - mysql

I am new to MySQL Workbench, so this could be a basic error on my part, but I am not sure what to do.
I have imported data (both using Data Import as well as running a script that includes schema creation) and I can see the schema exists in the Navigator. Likewise, I can run SQL queries on the schema with no problems.
However, when I go to File -> New Model, the schema is not there. I tried downloading another .sql file, created a schema for it and have the same problem.
Summary: I have schemas in MySQL Workbench that are not showing up in the Model section.

Chris M Perry answered this on Twitter for me:
"In any tab, you can click database -> reverse engineer and then follow the steps in selecting the schema."

Related

Migrate Table Data Only from MSSQL to MySQL

Been tasked with moving a code first database from MSSQL to MySQL. After a few hours of kung fu, I was able to get the asp.net core project to properly deploy all migrations to mysql. Now I need to migrate the data inside of the existing mssql tables. I saw posts mentioning MySQL Migration Toolkit but that appears to be old. Also attempted to do so with MySQL Workbench and DBLoad's Data Loader but haven't had any luck.
Table structure is pretty simple with incremental integer keys + the usual crap with asp.net core identify framework (GUID). Just need to keep that consistent during the migration. What is the best way to migrate the data now that the table structure is setup in MySQL? Any recommendations would be greatly appreciated!
Update: Some more details...
I attempted a direct migration of the database from MSSQL to MySQL using MySQL WorkBench and DBLoader. But failed on the ASP.net Identity tables big time plus other issues. .net core api took a huge dump in multiple places so that idea is out.
From that point, I migrated the api controller over to mysql and then had to fix a myriad of issues related to mssql fks being too long and a few other issues.
So at this point, the controller works on mysql. I just need to dump all of the data into MySQL and keep the FKs consistent.
I have had a few thoughts with it such as CSV export>import and/or trying a few other things. Any recommendations?
You can use Data Export wizard built-in with SqlServer Management Studio (task -> Export Data)
or use SSIS package to migrate data.
Tried MySQL Workbench, DBLoad from DBLoad.com etc to migrate the data directly and they all failed.
So ended up finding a "solution"...
First off, I modified the ASP.net Core project with:
//services.AddDbContext<ApplicationDbContext>(options =>
// options.UseSqlServer(
// Configuration.GetConnectionString("DefaultConnection")));
services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySql(
Configuration.GetConnectionString("DefaultConnection")));
Then went to Package Manager Console and ran: update-database
This created all of the tables in MySQL.
Then opened up Microsoft SQL Management Studio. Right clicked on the database Tasks > Generate Scripts. Saved everything to one file with Advanced option Schema and Data selected.
Then opened the db script in Notepad++ and applied the following edits using Replace with Extended Search Mode enabled:
GO -> blank
[dbo]. -> blank
[ -> blank
] -> blank
)\r\n -> );\r\n
\r\n' -> '
DateTime2 -> DATETIME
After edits were made in Notepad++, I removed all of the SET, ALTER and CREATE related stuff from the text file and then copied all of the insert lines into MySQL Workbench in order to ensure foreign keys were already populated before that table's data was inserted. Thank goodness there were no Stored Procedures to deal with! What a pain in the tucus!
Also on a side note, the app is hosted on Azure. Spent a couple of hours fighting the API not connecting to the database. This was not apparent at first as the app was fake throwing a 404 error to Postman. When I first attempted to wire up the API controllers to the MySQL DB, I entered the database connection string into Azure's App Service Configuration. It didn't work at all even though running the app locally worked fine. Ended up finding another post on this here site mentioning to get rid of the database connection string out of the App Service > Configuration window. Worked like a champ after that. All of the data with its auto incremented keys linked up without issue.
I am very pleased with the results and hope I never have to go through this process again! It is always a nice feeling to know an app now runs on a completely open source infrastructure. Hope this helps someone. Good luck.

MySQL Workbench: Refactoring Script

We have to make some changes to our databases (creating tables, Running special SQL queries).
Is there some way in MySQL Workbench to import a structure, edit it with a graphical interface and then getting some piece of SQL Code that I can use to transform my old structure into the new structure?
To explain my problem a bit further:
I need a way to transform my MySQL database structure to a new structure (adding databases and values into those tables) without interrupting the production environment for too long.
I would prefer a solution in MySQL Workbench (I'm using version 6.3)
but also accept any other answer to do this (for free)
Okay, I actually found a solution!!
What I was looking for is called an "SQL ALTER Script" or a Schema Sync.
Steps to generate a SQL Alter Script with MySQL Workbench:
Open MySQL Workbench
Click File -> New Model
Click Database -> Synchronize With Any Source
Click Next
Select a SQL Dump File as Source (this is the new structure)
Select a SQL Dump File as Destination (this is the old structure)
At Send Updates To select a Folder and Filename where the ALTER Script will be placed.
Click Next
Click Next
Make sure default_schema is checked and Click Next
Click Next
Preview your SQL Code and Click Next
You now successfully generated your SQL Alter Script and it got saved into the specified file.
But Note that you will have to open the SQL File in an editor and replace default_schema with your database name

Creating a database with MySQL Workbench from existing schema/model

I built a database schema (or Model?) with MySQL Workbench. I'd like to now make it into an actual database.
I've seen Forward and Reverse engineer options and can't find a clear answer on if either are what I need.
How can I turn this into an actual database?
This for mysql workbench version 6.0 and for exporting a schema.
Select tab MySQL Model
Select File->Export->Forward Engineer SQL Create
Place a file name to be exported in the Output SQL Script File, choose your options, next
Export MySQL table Objects,
filter tables
Then a file is created which you can import to your database and it creates schemas if not exists, creates tables if not exists.
In the case of models, you need to pay, many bucks, for a tool that creates schemas, tables, indexes, cascading, and all stuff associated to an existing data model.
In order to realize a modeled schema structure on a real server you would use either forward engineering or synchronization. The first is if you have just the model and want it to create all the objects in the target schema(s). Synchronization on the other hand is a means to synchronize your model and an existing schema (two-way). That is, objects not existing or changed in your model are created or adjusted on the server and vice versa. There's no need to create a separate SQL script and apply that manually.
For both action see the Database menue in MySQL Workbench when a model is open.
The official documentation has a relevant article. http://dev.mysql.com/doc/workbench/en/wb-getting-started-tutorial-creating-a-model.html
Jump to step 11.
As of MySQL Workbench 8.0, go to the menu item Database > Forward Engineer. After specifying your database connection and model export options, you’ll be able to create the database you have designed.
See MySQL Workbench Manual :: 9.4.1.2 Forward Engineering to a Live Server for details.

How to do a query in Mysql WorkBench?

I have an .sql script that contains inserts and creates tables. I used the "Create EER Model From Script"
It created the tables but I can't see the data inside these tables.
I went to the query menu and tried to make a query but it gives me an error about not being able to connect to localhost.
Am I doing it right?
As documented under Create EER Model from SQL Script:
Clicking this action item launches the Reverse Engineer SQL Script wizard. This is a multi-stage wizard that enables you to select the script you want to create your model from.
For further information, see Section 7.7.9.1, “Reverse Engineering Using a Create Script”.
Following that link:
However, if you are working with a script that also contains DML statements you need not remove them; they will be ignored.
Instead, you want the Manage Data Import/Export option under Server Administration (within the Workspace section of the Home window).
You are confusing things here. Creating a model from a script is a process where meta data is examined and a model is created that you can then use to modify your schema structure, further design your db objects and all that. Modeling is a design process for the structure of your schema/db so it only deals with meta data. It's also used for documentation (e.g. in teams).
On the other hand there's normal sql work with existing db objects and/or actually creating/deleting/modifying db objects. In order to do the latter you must have an understanding of the design of the schema (which you could get by using the modeling part of MySQL Workbench, but not only by that). This is also the place to load a script, run it to insert data and such.
The error you mentioned regarding the connection is yet another problem and you need to solve this first to be able to even access your server. And yes, you have to install a server first somewhere. MySQL Workbench is a tool to visually work with your server(s) in opposition to the MySQL command line client which is a pure text interface (but still also a client application for your MySQL servers).
If you are on Windows and want a MySQL server installed locally (e.g. for testing) your best option is to download the MySQL Installer which greatly simplifies installing any of the tools from the MySQL family (server, client tools, connectors, documentation and more).

How to generate the whole database script in MySQL Workbench?

I want to take the whole database. Where do I find the database file?
And is there a way to write the whole database with all data to a text file (like the one in SQL Server)?
How to generate SQL scripts for your database in Workbench
In Workbench Central (the default "Home" tab) connect to your MySQL instance, opening a SQL Editor tab.
Click on the SQL Editor tab and select your database from the SCHEMAS list in the Object Browser on the left.
From the menu select Database > Reverse Engineer and follow the prompts. The wizard will lead you through connecting to your instance, selecting your database, and choosing the types of objects you want to reverse engineer.
When you're all done, you will have at least one new tab called MySQL Model. You may also have a tab called EER Diagram which is cool but not relevant here.
Click in the MySQL Model tab
Select Database > Forward Engineer
Follow the prompts. Many options present themselves, including Generate INSERT Scripts for Tables which allows you to script out the data contained within your tables (perfect for lookup tables).
Soon you will see the generated script in front of you. At this point you can Copy to Clipboard or Save to Text File.
The wizard will take you further, but if you just want the script you can stop here.
A word of caution: the scripts are generated with CREATE commands. If you want ALTER you'll have to (as far as I can tell) manually change the CREATEs to ALTERs.
This is guaranteed to work, I just did it tonight.
Q#1: I would guess that it's somewhere on your MySQL server?
Q#2: Yes, this is possible. You have to establish a connection via Server Administration. There you can clone any table or the entire database.
This tutorial might be useful.
EDIT
Since the provided link is no longer active, here's a SO answer outlining the process of creating a DB backup in Workbench.
In MySQL Workbench 6, commands have been repositioned as the "Server Administration" tab is gone.
You now find the option "Data Export" under the "Management" section when you open a standard server connection.
there is data export option in MySQL workbech
I found this question by searching Google for "mysql workbench export database sql file". The answers here did not help me, but I eventually did find the answer, so I am posting it here for future generations to find:
Answer
In MySQLWorkbench 6.0, do the following:
Select the appropriate database under MySQL Connections
On the top-left hand side of screen, under the MANAGEMENT heading, select "Data Export".
Here is a screenshot for reference:
None of these worked for me. I'm using Mac OS 10.10.5 and Workbench 6.3. What worked for me is Database->Migration Wizard... Flow the steps very carefully
In the top menu of MySQL Workbench click on database and then on forward engineer. In the options menu with which you will be presented, make sure to have "generate insert statements for tables" set.
Try the export function of phpMyAdmin.
I think there is also a possibility to copy the database files from one server to another, but I do not have a server available at the moment so I can't test it.
Using Windows 10 and MySql Workbench 8.0
Go to Server tab
Go to Database Export
This opens up something like this
Select the schema to export in the Tables to export
Click the button Start Export
Surprisingly the Data Export in the MySql Workbench is not just for data, in fact it is ideal for generating SQL scripts for the whole database (including views, stored procedures and functions) with just a few clicks. If you want just the scripts and no data simply select the "Skip table data" option. It can generate separate files or a self contained file. Here are more details about the feature: http://dev.mysql.com/doc/workbench/en/wb-mysql-connections-navigator-management-data-export.html
in mysql workbench server>>>>>>export Data
then follow instructions it will generate insert statements for all tables data each table will has .sql file for all its contained data