You can use MySQL Workbench to run a query, then export the results of that query to a file.
To do this:
- Run the query
- Click Export on the Results Grid menu bar
To create a relationship in MySQL Workbench:
- Create a database model (either create a new model or reverse engineer an existing database)
- Viewing the database model, double click on the first table of the relationship
- The bottom pane will open with the table details. Click on the Foreign Keys tab
- In the left pane, select the foreign key field and referenced table
- In the middle pane, select the foreign column and referenced (primary key) column
- In the right pane, set any Update/Delete actions you’d like to occur when a primary key record is updated or deleted
The relationship is now established. Repeat steps 4 to 6 for any other foreign key columns in that table.
To reverse engineer a database in MySQL Workbench:
- Select Database > Reverse Engineer from the top menu of MySQL Workbench
- Set/review parameters for connecting to the DBMS then click Continue
- Enter password if required, then click OK
- The wizard will connect to the DBMS, fetch a list of databases, and check for any issues. Click Continue
- Select the database/s you would like to reverse engineer, then click Continue
- The wizard will retrieve all objects from the selected schema/s and check the results. Click Continue
- Select the database objects you’d like to have reverse engineered, then click Execute
- The wizard will now reverse engineer all selected objects and generate the EER diagram (behind the scenes). Click Continue
- A summary is displayed. Click Close
The EER diagram is now displayed on the screen.
To stop/start MySQL using MySQL Workbench:
- Select Server > Startup/Shutdown from the top menu
- A tab will open showing whether the server is stopped or started. Click either Stop Server or Start Server as required.
Here are screenshots for the above steps.
To generate a script from a diagram in MySQL Workbench:
- Select File > Export > Forward Engineer SQL CREATE Script...
- Enter a location to save the file (optional) and set options to include on the script (such as DROP statements etc), then click Continue
- Exclude any objects by deselecting them, otherwise leave them as is, then click Continue
- The script is generated. You can copy it to your clipboard or click Finish to save it to a file
To create a new database diagram using MySQL Workbench:
- Click File > New Model from the menu
- Create a new schema by clicking the + icon next to Physical Schemas
- Add tables by clicking Add Tables, then add/configure their columns in the bottom pane.
- Create relationships and any other configurations by using the various tabs
- Create a diagram by clicking Model > Create Diagram from Catalog Objects
The diagram will be created. You can rearrange the tables to a more suitable layout by clicking and dragging.
To view MySQL status and system variables via MySQL Workbench, click on Status and System Variables under the Management tab in the left navigation pane.
The “Status and System Variables” option allows you to view a list of all variables for the MySQL connection.
This launches the Status and System Variables screen.
To check user privileges in MySQL Workbench, click Users and Privileges on the Management tab of the left navigation pane:
Clicking on “Users and Privileges” in the left navigation pane.
This opens the Users and Privileges screen on the Login tab.
You can use MySQL Workbench to view current connections in MySQL either by query or by GUI.
- By Query: Run SHOW PROCESSLIST; in a query tab.
- By GUI: Click on Client Connections in the Management tab of the left navigation pane.
To check the status of a MySQL server using the MySQL Workbench GUI:
- Click the MySQL connection (as you would normally do when connecting via MySQL Workbench)
- Click Server Status from the Management tab in the left navigation pane
The Server Status window will appear, displaying the server’s status and related information: