04_Managing_Objects

The Object Browser allows you to navigate database schemas and objects. From here, you can perform common tasks such as selecting tables and fields to query, edit tables, create new or drop tables and databases, perform searches, and more.

Object Browser and Editor Navigator

The Navigator contains options to manage the active MySQL connection, and also lists the schemas available to that connection.

The Schemata list shows available schemata on the currently connected server. These can be explored to show tables, views, and routines within the schema.

Note

Internal schemas, such as “performance_schema”, “information”schema“,”sys“, and”mysql“, are hidden by default. Toggle the Show Metadata and Internal Schemas preference to list them in the object browser. Schemas beginning with a”." are also controlled by this setting.

Figure 8.23 SQL Editor - Navigator Schemas Tab

SQL Editor - Navigator Schemas Tab

It is possible to set a schema as the default schema by right-clicking the schema and selecting the Set As Default Schema menu item. This executes a USE schema_name statement so that subsequent statements without schema qualifiers are executed against this schema. This setting applies only to the query session. To set a default schema for multiple MySQL Workbench sessions, you must set the default schema for the stored connection. From the Home screen, right-click on a MySQL connection, choose Edit Connection, and set the desired default schema on the Default Schema box.

Note

The selected schema is displayed as bold in the Schema navigator.

Double-clicking a table, view, or column name in the schemata explorer inserts the name into the SQL Query area. This reduces typing significantly when entering SQL statements containing references to several tables, views, or columns.

The Schema Navigator also features a context menu which can be displayed by right-clicking an object. For example, right-clicking a table displays the following menu items:

  • Select Rows - Limit 1000: Pulls up to 1000 rows of table data from the live server into a Results tabsheet, and enables editing. Data can be saved directly to the live server.

  • Table Inspector: Displays table information, similar to the Schema Inspector. This also has a simpler and easier to use interface for analyzing and creating indexes for tables.

  • Table Data Export: Opens the table export wizard to export the table’s data to JSON or customized CSV.

  • Table Data Import: Opens the table import wizard to import JSON or CSV formatted data to the selected or new table.

  • Copy to Clipboard: There are various submenus, each of which copies information to the clipboard:

    • Name (short): Copies the table name.

    • Name (long): Copies the qualified table name in the form `schema`.`table`.

    • Select All Statement: Copies a statement to select all columns in this form:

      SELECT
      `table`.`column1`,
      `table`.`column2`,
      ...
      FROM `schema`.`table`;
    • Insert Statement: Copies an INSERT statement to insert all columns.

    • Update Statement: Copies an UPDATE statement to update all columns.

    • Delete Statement: Copies a DELETE statement in the form DELETE FROM `world`.`country` WHERE ;.

    • Create Statement: Copies a CREATE statement in the form DELETE FROM `world`.`country` WHERE ;.

    • Delete with References: Copies a DELETE statement, in the form of a transaction, that deletes all objects that reference the row (directly or indirectly).

      Use Select with References first to preview this operation.

    • Select with References: Copies a SELECT statement that selects all objects that reference the row (directly or indirectly).

      Use Delete with References to generate a DELETE statement for this operation.

  • Send to SQL Editor: Provides functionality similar to Copy to Clipboard. However, this item inserts the SQL code directly into the SQL Query panel, where it can be edited further as required.

  • Create Table: Launches a dialog to enable you to create a new table.

  • Create Table Like…: Launches a dialog to enable you to create a new table, and to also apply predefined templates. For additional information, see Section 9.6, “Table Templates”.

  • Alter Table…: Displays the table editor loaded with the details of the table.

  • Table Maintenance: Opens a new tab for performing table maintenance operations. Operations include “Analyze Table”, “Optimize Table”, “Check Table”, and “Checksum Table”. Additional information about the table may also be viewed from this tab. For additional information, see Schema Inspector.

  • Drop Table…: Drops the table. All data in the table will be lost if this operation is carried out.

  • Truncate Table…: Truncates the table.

  • Search Table Data…: Opens a new tab for performing table searches. It performs a search on all columns, and offers additional options to limit the search.

  • Refresh All: Refreshes all schemata in the explorer by resynchronizing with the server.

Right-clicking on a schema provides similar options to the table context menu described above, but the operations refer to the Schema. For example, the Table Maintenance in the table context menu selects the table in the Schema Inspector, which is a schema context menu option.

Session and Object Information Panel

This panel summarizes the current connection to the server.

Figure 8.24 SQL Editor - Connection Information Palette

SQL Editor - Connection Information Palette

This panel also summarizes information about the object.

Figure 8.25 SQL Editor - Object Info

SQL Editor - Object Info

Schema and Table Inspector

The Schema and Table Inspector includes the ability to analyze and repair tables, and also view table metrics.

Schema Inspector

Use the Schema Inspector to browse general information from schema objects. It allows you to perform maintenance tasks on tables such as ANALYZE, OPTIMIZE, CHECK, and CHECKSUM TABLE. To access the inspector, right-click on a schema and select the Schema Inspector

Figure 8.26 Schema Inspector

Schema Inspector

Each tab lists topic oriented information, such as “Tables”, “Indexes”, and “Triggers”. From the Tables tab, click Inspect Table to open the Table Inspector, or Maintenance to open the table maintenance tools:

Figure 8.27 Schema Inspector: Table Maintenance

Schema Inspector: Table Maintenance

Table Inspector

Table Inspector

View table information, similar to the Schema Inspector. This also has a simpler and easier to use interface for analyzing and creating indexes for your tables.

To open, right-click on a table in the object browser and choose Table Inspector from the context menu.

Figure 8.28 Open the Table Inspector

Open the Table Inspector

The Table Inspector shows information related to the table.

Figure 8.29 Table Inspector: Info Tab

Table Inspector: Info Tab