Dear readers of our blog, we'd like to recommend you to visit the main page of our website, where you can learn about our product SQLS*Plus and its advantages.
 
SQLS*Plus - best SQL Server command line reporting and automation tool! SQLS*Plus is several orders of magnitude better than SQL Server sqlcmd and osql command line tools.
 

REQUEST COMPLIMENTARY SQLS*PLUS LICENCE

Enteros UpBeat offers a patented database performance management SaaS platform. It proactively identifies root causes of complex revenue-impacting database performance issues across a growing number of RDBMS, NoSQL, and deep/machine learning database platforms. We support Oracle, SQL Server, IBM DB2, MongoDB, Casandra, MySQL, Amazon Aurora, and other database systems.

MySQL Workbench. Database creation

9 June 2020

MySQL Workbench. Database creation

MySQL Workbench – A web developer grows with the projects he creates and develops. As the projects grow, the complexity of the software part increases, the amount of data processed by it inevitably increases, as well as the complexity of the data schema. Interaction with other web developers shows that MySQL databases are very popular among us, and to manage them – the well-known PHPMyAdmin.

Moving from small projects to large, from cms to frameworks, many, like me, remain true to MySQL. However, to design a complex database with a large number of tables and links, the capabilities of PHPMyAdmin are catastrophically lacking. So I decided to write an overview of MySQL Workbench – a great free desktop program for working with MySQL.

MySQL Workbench is a database design tool

MySQL Workbench is a database design tool that integrates database design, modeling, creation and operation into a single seamless environment for the MySQL database system.

MySQL Workbench. Database creation

I must say, the program is really great. It allows you to quickly and gladly encapsulate the schematics of the project data, design the entities and connections between them, painlessly implement changes to the scheme and just as quickly and painlessly synchronize it with a remote server. And the graphic editor of EER-diagrams, reminiscent of funny cockroaches, allows you to see the overall picture of the data model and enjoy its lightness and elegance. After the first try, this tool becomes an indispensable assistant in the combat arsenal of web programmer.

Download MySQL Workbench

The MySQL Workbench distribution is available on this page. The latest version of the program at the time of writing is Version 6.1. Before downloading, you need to select one of the following platforms:

  • Microsoft Windows (MSI Installer and ZIP archive are available).
  • Ubuntu Linux
  • Fedora
  • Red Hat Enterprise Linux / Oracle Linux
  • Mac OS X

Once you have selected a platform, you are invited to register or log in to Oracle. If you do not want, there is a link “No thanks, just start my download” below – click on it.

Getting started with MySQL Workbench

The start screen of the program reflects the main directions of its functionality – design of database models and their administration:

Getting started with MySQL Workbench

In the upper part of the screen there is a list of connections to MySQL servers of your projects, and a list of the latest open data models – at the bottom of the screen. The work usually starts with creating a data schema or loading an existing structure into MySQL Workbench. Let’s get to work!

Creating and editing a data model

To add a model, press the plus sign next to the “Models” heading or select “File → New Model” (Ctrl + N):

Creating and editing a data model

On this screen, enter a name for the database, select the default encoding and fill in the comment box if necessary. You can start creating tables.

Adding and editing a table

The list of project databases and the list of tables within the database will be located in the “Physical Schemas” tab. To create a table, double-click on “+Add Table”:

Adding and editing a table

This opens a user-friendly interface for editing the list of fields and their properties. Here we can set the field name, data type, as well as set different attributes for the fields: assign the field as Primary Key (PK), mark it as Not Null (NN), BIN, Unique (UQ) and others, set the field to auto-increment (AI) and default (Default).

Index management

You can add, delete and edit table indexes in the “Indexes” tab of the table management interface:

Index management

Enter the name of the index, select its type, then check the list of fields participating in this index in the required order. The order of the fields will correspond to the order in which the checkboxes were placed. In this example, I added a unique index to the username field.

The installation of external keys and linking of tables is only possible for InnoDB tables (this storage system is selected by default). To manage the bindings, each table has a “Foreign Keys” tab:

Links between tables

To add a connection, open the “Foreign Keys” tab of the child table, enter the name of the external key and select the parent table. Then in the middle part of the tab in the column Column, select the key field from the child table, and in the column Referenced Column – the corresponding field from the parent table (the type of fields must match). When creating external keys in the child table, the corresponding indexes are automatically created.

In the “Foreign Key Options” section, we configure the behavior of the external key when changing the corresponding field (ON UPDATE) and deleting (ON DELETE) the parent record:

  • RESTRICT – generate an error when changing/deleting a parent record
  • CASCADE – update the external key when changing the parent record, delete the child record when deleting the parent
  • SET NULL – set the value of the external key NULL when changing / removing the parent (unacceptable for fields that have NOT NULL flag set!).
  • NO ACTION – do nothing, but in fact the effect is similar to RESTRICT.

In the example above, I added an external key to the UserProfile child table to link to the User parent table. When editing the userId field and removing items from the User table, similar changes will automatically happen to the associated entries in the UserProfile table.

Filling the table with basic data

When creating a project, you often need to add start data to the database. These can be root categories, user admins, etc. In the MySQL Workbench table management there is an “Inserts” tab for this purpose:

Filling the table with basic data

As you can see from the example, if you need to apply some MySQL function to data before writing it to the database, this is done using the \func functionName(‘data’) syntax, for example, \func md5(‘password’).

After entering data, you should save it to the local database by clicking the “Apply Changes” button.

Creating an EER diagram (entity-communication diagram)

There is an EER-diagram editor for representing the data schema, entities and their relationships graphically in MySQL Workbench. To create a diagram, double-click the “+Add Diagram” icon at the top of the database management screen:

Creating an EER diagram (entity-communication diagram)

In its interface you can create and edit tables, add different types of connections between them. To add a table that already exists in a chart to a chart, simply drag and drop it from the Catalog Tree panel.

Catalog Tree panel

To export the schematic data to a graphic file, select “File → Export” and then one of the options (PNG, SVG, PDF, PostScript File).

Importing an existing data schema (from SQL dump)

If we already have a data schema, you can easily import it into MySQL Workbench for further work. To import a model from an SQL file select “File → Import → Reverse Engineer MySQL Create Script…”, then select the desired SQL file and click “Execute >”.

Importing an existing data schema (from SQL dump)

MySQL Workbench also provides for importing and synchronizing data models directly with a remote server. To do this, you need to create a remote access connection to MySQL.

MySQL Workbench Tutorial. Introduction To MySQL Workbench. MySQL DBA Training. Edureka (video)

 
Tags: , , ,

MORE NEWS

 

Preamble​​NoSql is not a replacement for SQL databases but is a valid alternative for many situations where standard SQL is not the best approach for...

Preamble​​MongoDB Conditional operators specify a condition to which the value of the document field shall correspond.Comparison Query Operators $eq...

5 Database management trends impacting database administrationIn the realm of database management systems, moreover half (52%) of your competitors feel...

The data type is defined as the type of data that any column or variable can store in MS SQL Server. What is the data type? When you create any table or...

Preamble​​MS SQL Server is a client-server architecture. MS SQL Server process starts with the client application sending a query.SQL Server accepts,...

First the basics: what is the master/slave?One database server (“master”) responds and can do anything. A lot of other database servers store copies of all...

Preamble​​Atom Hopper (based on Apache Abdera) for those who may not know is an open-source project sponsored by Rackspace. Today we will figure out how to...

Preamble​​MongoDB recently introduced its new aggregation structure. This structure provides a simpler solution for calculating aggregated values rather...

FlexibilityOne of the most advertised features of MongoDB is its flexibility.  Flexibility, however, is a double-edged sword. More flexibility means more...

Preamble​​SQLShell is a cross-platform command-line tool for SQL, similar to psql for PostgreSQL or MySQL command-line tool for MySQL.Why use it?If you...

Preamble​​Writing an application on top of the framework on top of the driver on top of the database is a bit like a game on the phone: you say “insert...

Preamble​​Oracle Coherence is a distributed cache that is functionally comparable with Memcached. In addition to the basic function of the API cache, it...

Preamble​​IBM pureXML, a proprietary XML database built on a relational mechanism (designed for puns) that offers both relational ( SQL / XML ) and...

  What is PostgreSQL array? In PostgreSQL we can define a column as an array of valid data types. The data type can be built-in, custom or enumerated....

Preamble​​If you are a Linux sysadmin or developer, there comes a time when you need to manage an Oracle database that can work in your environment.In this...

Preamble​​Starting with Microsoft SQL Server 2008, by default, the group of local administrators is no longer added to SQL Server administrators during the...