Creating a Table in MySQL
The purpose of this appendix is to familiarize the reader with the MySQL Workbench, enabling him or her to create, display, edit and delete MySQL database tables independent of Syndeia.
Connecting to a MySQL Database through MySQL Workbench
- In order to connect to a MySQL repository directly, install the MySQL Workbench client on your local computer and contact the MySQL server administrator for a user name, password and the server hostname.
Launch MySQL Workbench from your local computer and select Database → Connect to Database.
- Entering the information provided by the administrator into the window, create a quick connection path on the workbench desktop. The Stored Connection field should contain a nickname assigned by the user for easy identification.
- There should now be an icon on the MySQL Workbench desktop label with the Stored Connection name. Click it to open the SQL Editor window.
Creating a MySQL Database Schema
- It is possible to create a table in one of the existing schemas shown in the lower left corner, skipping this section. Alternatively, a new schema can be created by clicking the Create New Schema icon, shown in green in the same figure. This opens the Schema tab.
- Assign the new schema a name and click Apply. A new window will appear that shows the SQL commands that create the new schema. Review and click Apply again. A final window prepares to execute the commands. Click Finish to complete.
Creating a MySQL Database Table
- To create a new table, begin by selecting which of the available schemas to create the table in. Right-click on the desired schema in the lower left corner and select Set as Default Schema. The selections should now appear in bold font.
- Click on the Create New Table icon (see yellow highlight).
- Enter the new table's name in the first field. Check that the Schema to the right is correct.
- Expand the Window vertically, if necessary, to see several rows of the table headed Column Name…Datatype and enter column header information for the new table, as shown. Generally the first column entered will be set as primary key, but this can be changed by checking the PK and NN (Not Null) columns. When finished, click Apply. Respond with Apply and Finish, respectively.
To display and edit the contents of the table, enter the command shown below in the Query 1 tab (shown for table Staff in schema test_demo) and click on the Execute icon.
- As shown, enter the data into the table in the lower pane. In this example, we show a table with two columns (employee and desk) and four rows. When all data has been entered, click Apply, Apply and Finish as before.
Copyright 2018 Intercax.