0% found this document useful (0 votes)
7 views

Chapter 2 slides

Chapter 2 provides a comprehensive guide on using MySQL Workbench and the MySQL Command Line Client, detailing how to start the MySQL server, create and manage database connections, and execute SQL statements. It includes step-by-step instructions for viewing and editing database tables, as well as handling SQL scripts and syntax errors. Additionally, it offers insights into the MySQL Reference Manual and command-line operations for managing databases.

Uploaded by

tenacitycreator
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Chapter 2 slides

Chapter 2 provides a comprehensive guide on using MySQL Workbench and the MySQL Command Line Client, detailing how to start the MySQL server, create and manage database connections, and execute SQL statements. It includes step-by-step instructions for viewing and editing database tables, as well as handling SQL scripts and syntax errors. Additionally, it offers insights into the MySQL Reference Manual and command-line operations for managing databases.

Uploaded by

tenacitycreator
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Chapter 2

How to use
MySQL Workbench
and other
development tools

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 1
Objectives
Applied
1. Start or stop the MySQL database server.
2. Use MySQL Workbench to do any of the following:
Create a database connection
Navigate through the objects of a database
View the column definitions for a table
View the data for a table
Edit the column definitions for a table
3. Use MySQL Workbench to enter, run, open, and save SQL
statements and scripts.
4. Use the MySQL Reference Manual to look up information about
SQL statements.
5. Use MySQL Command Line Client to run a SQL statement.

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 2
Objectives (continued)
Knowledge
1. Describe the function of each of these client tools: the MySQL
Command Line Client, MySQL Workbench, and the MySQL
Reference Manual.

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 3
The Home page of MySQL Workbench

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 4
The dialog box for opening database connections

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 5
How to connect as the root user
1. Click the stored connection for the local instance.
2. Enter a password if prompted.
How to specify your own connection parameters
1. Right-click the connection and select Edit Connection.
2. Enter the connection parameters and click the Close button.
How to create a new connection
1. Click the + icon to the right of MySQL Connections
2. Enter the connection parameters and click the OK button.

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 6
How to save a password
 Check the “Save password in vault” option when prompted for
your password.

How to clear a password


1. Right-click the connection.
2. Select Edit Connection.
3. Click the Clear button for the password.
4. Click the Close button.

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 7
The Server Status option of MySQL Workbench

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 8
How to view the status of the database server
1. Connect to the local server and enter the password if prompted.
2. Display the Administration tab of the Navigator window.
3. Select the Server Status option from the Management category.

Note
 After you install MySQL, the database server usually starts
automatically each time you start your computer.

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 9
The tables available for the AP database

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 10
The data for the Invoices table in a Result grid

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 11
How to view the data for a table
1. Right-click the table in the Navigator window.
2. Select Select Rows - Limit 1000 to display it in a Result grid.

How to edit the data for a table


3. View the data.
4. Use the buttons at the top of the Result grid to insert, update, and
delete rows.
5. Click the Apply button at the bottom of the tab to apply changes.

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 12
The column definitions for the Vendors table

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 13
How to view the column definitions
1. Right-click the table name in the Navigator window.
2. Select Alter Table.

How to edit the column definitions


3. View the column definitions.
4. Use the resulting window to add new columns and modify and
delete existing columns.

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 14
A SELECT statement and its results

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 15
How to enter a SQL statement
1. Press Ctrl+T or click the Create New SQL Tab button in the SQL
Editor toolbar to open a new SQL Editor tab.
2. Double-click a database in the Schemas tab of the Navigator
window to select it.
3. Type the SQL statement into the SQL editor.

How to execute a SQL statement


4. Press Ctrl+Enter or click the Execute Statement button in the SQL
Editor toolbar.
5. If the statement retrieves data, the data is displayed in a Result
grid.

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 16
How to handle syntax errors

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 17
Common causes of errors
 Having the wrong database selected
 Misspelling the name of a table or column
 Misspelling a keyword
 Omitting the closing quotation mark for a character string

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 18
The Open SQL Script dialog box

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 19
How to open a SQL script
1. Click the Open SQL Script File button in the SQL Editor toolbar or
press Ctrl+Shift+O.
2. Use the Open SQL Script dialog box to locate and open the SQL
script.

How to switch between open files


 Select the appropriate tab.

How to cut, copy, and paste code


 Use the standard techniques.

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 20
How to save a new SQL script
1. Click the Save button in the SQL Editor toolbar or press Ctrl+S.
2. Use the Save SQL Script dialog box that’s displayed to specify a
location and name for the file.

How to save a modified script to a new file


3. Press Ctrl+Shift+S or select FileSave Script As.
4. Use the Save SQL Script dialog box that’s displayed to specify a
location and name for the file.

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 21
A SQL script and its results

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 22
How to run an entire script
 Press Ctrl+Shift+Enter or click the Execute Script button.

How to run one statement within a script


1. Move the insertion point into the statement you want to execute.
2. Press Ctrl+Enter or click the Execute Statement button.

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 23
How to run two or more statements within a script
1. Select the statements you want to execute.
2. Press Ctrl+Shift+Enter or click the Execute Script button.

Notes
 The results of each statement that returns data are displayed in a
separate Result grid.
 If a script contains more than one statement, you must code a
semicolon at the end of each statement.

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 24
The web address for the MySQL 8.0 Reference
Manual
https://dev.mysql.com/doc/refman/8.0/en/

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 25
A web page from the MySQL Reference Manual

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 26
The MySQL Command Line Client in Windows

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 27
How to start the MySQL Command Line Client
from the command line
For Windows
cd \Program Files\MySQL\MySQL Server 8.0\bin
mysql –u root -p

For macOS
cd /usr/local/mysql/bin
./mysql –u root -p

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 28
The syntax of the mysql command
mysql –h hostname –u username –p

Examples of the mysql command


mysql –u ap_tester -p
mysql –h localhost –u root –p
mysql –h murach.com –u ap_tester –p

How to exit from the MySQL Command Line


Client
mysql> exit;

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 29
How to list the names of all databases
managed by the server
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| ap |
| ex |
| information_schema |
| mysql |
| om |
| performance_schema |
| sys |
+--------------------+
7 rows in set (0.00 sec)

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 30
How to select a database for use
mysql> use ap;
Database changed

How to select data from a database


mysql> select vendor_name from vendors limit 5;
+------------------------------+
| vendor_name |
+------------------------------+
| Abbey Office Furnishings |
| American Booksellers Assoc |
| American Express |
| ASC Signs |
| Ascom Hasler Mailing Systems |
+------------------------------+
5 rows in set (0.00 sec)

© 2023, Mike Murach & Associates, Inc.


Murach's MySQL 4th Edition C2, Slide 31

You might also like