> For the complete documentation index, see [llms.txt](https://docs.snomed.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.snomed.org/snomed-ct-practical-guides/snomed-ct-sql-practical-guide/appendices/appendix-a-building-the-snomed-ct-example-database/a5-using-mysql-workbench-to-query-snomed-ct.md).

# A.5 Using MySQL Workbench to Query SNOMED CT

## Creating and Configuring a SNOMED CT Connection

### Open MySQL Workbench Application

<div align="left"><figure><img src="/files/HzbxYRBm4MY3nZzR6AyX" alt=""><figcaption></figcaption></figure></div>

The following dialog should be displayed.

<figure><img src="/files/ECQBOgSM1c2AJ0w9XcMx" alt=""><figcaption></figcaption></figure>

### Create a SNOMEDCT Connection

* Click the spanner symbol to the right of the **MySQL Connections** prompt.

<figure><img src="/files/GAROtRcBJpOnNxeGsZst" alt=""><figcaption></figcaption></figure>

When the dialog below opens:

* Select the default MySQL connection
* Then click the **Duplicate** button

<figure><img src="/files/b42nvKiVKwBXK40DBVcj" alt=""><figcaption></figcaption></figure>

With the newly created connection selected:

* Change the Connection Name to **SNOMEDCT**
* Enter a Default Schema name as **snomedct** (i.e. the name of the newly created database)

<figure><img src="/files/8VkkNtg3uvdpcmDoj9fg" alt=""><figcaption><p>* Click the</p></figcaption></figure>

* Click the button:

<div align="left"><figure><img src="/files/IvRefqGXJFFIGNoSGl4A" alt=""><figcaption></figcaption></figure></div>

* If the connection is successful you will see the following dialog.

<div align="left"><figure><img src="/files/REDF8tuJtSxnsrIcF7DI" alt="" width="375"><figcaption></figcaption></figure></div>

In future when you open MySQL Workbench you will see the option to open the SNOMEDCT connection.

<figure><img src="/files/qDDu37Qna5cZHajnsnfo" alt=""><figcaption></figcaption></figure>

### Save Your MySQL Password in Keychain

To avoid future prompts for the MySQL Password you can save the password in the Keychain.

* Click the button

<div align="left"><figure><img src="/files/d0CJSBK8ncNvDEYIKa4N" alt=""><figcaption></figcaption></figure></div>

* Enter the MySQL password to be stored.

<div align="left"><figure><img src="/files/2exTyuxlCwukw6c1fFgb" alt="" width="563"><figcaption></figcaption></figure></div>

## Testing and Using the SNOMED CT Database

### Open the SNOMEDCT Connection

* Open MySQL Workbench
* Select the SNOMED CT Connection

<figure><img src="/files/qDDu37Qna5cZHajnsnfo" alt=""><figcaption></figcaption></figure>

### Test the SNOMED CT Database

To test the loaded SNOMED CT database open one of the example queries in the **SnomedCtRfsMySql/mysql\_examples** folder.

* Click open SQL button in the toolbar

<div align="left"><figure><img src="/files/VpuxRD03egnWPLO5ggG2" alt=""><figcaption></figcaption></figure></div>

* Find the **mysql\_examples** folder in the SnomedCtRfsMySql subfolder of your home directory.
* Select and open one of the queries

<div align="left"><figure><img src="/files/rqDguolqCYouL0TdWhD2" alt="" width="563"><figcaption></figcaption></figure></div>

The query should be display as shown below

<div align="left"><figure><img src="/files/hHtocm900kvKuhnkWevR" alt="" width="563"><figcaption></figcaption></figure></div>

* Click the lightning icon <img src="https://confluence.ihtsdotools.org/download/thumbnails/96805396/image2019-9-9_11-24-8.png?version=1&#x26;modificationDate=1570894925000&#x26;api=v2" alt="" data-size="line"> to run the query

The results of running the query should be displayed as below

<div align="left"><figure><img src="/files/XoV3jk13wzUYJzBMlo4o" alt="" width="563"><figcaption></figcaption></figure></div>

<figure><img src="https://github.com/SNOMED-Documents/snomed-sql-guide/blob/main/images/96805415.png" alt=""><figcaption></figcaption></figure>

### Using the SNOMED CT Database

The SNOMED CT database can be used in different ways:

* Running example SQL queries in the SnomedRfsMySql package.
* Running queries provided as part of a SNOMED CT E-Learning assignment.
* Using example SQL queries as templates for your own queries.
* Running SQL queries you have written yourself from scratch.

You can run your SQL queries in MySQL Workbench as described in the previous section. Additionally these queries can be run using the MySQL command line interface or through a MySQL connector for one of the programming languages listed at: <https://dev.mysql.com/downloads/>.

{% hint style="danger" %}
If you are using example queries as templates for your own queries alway copy the query first so that you do not overwrite the original example query.

* If you accidentally overwrite an example query, you can download the SnomedRfsMySql.zip file again and extract the example queries folder.
  {% endhint %}

## Managing MySQL Accounts

The "root" user account is typically used for importing the SNOMED CT release files. However, you should create additional MySQL accounts for database users that do not have administrator rights. Ideally the name of these MySQL accounts should match the Mac username of the user as this simplifies call the mysql command line tool and the use of MySQL connectors.

To create user accounts in the MySQL Workbench select the **Administration** tab (see below) and select **Users and Privileges** (see below).

<div align="left"><figure><img src="/files/0cvzd99X7DgqZ8ky63rz" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://github.com/SNOMED-Documents/snomed-sql-guide/blob/main/images/96805400.png" alt=""><figcaption></figcaption></figure>

### Set up the account details and access permissions.

* In this example an account with the username **newuser** account is being created as shown below:

<figure><img src="/files/KEgda56SmcBAGF3HrZDk" alt=""><figcaption></figcaption></figure>

* In the schema privileges the **newuser** is given access to the **snomedct** database schema:

<figure><img src="/files/PGcb9NMgMF1H48zt7rXK" alt=""><figcaption></figcaption></figure>

<figure><img src="https://github.com/SNOMED-Documents/snomed-sql-guide/blob/main/images/96805398.png" alt=""><figcaption></figcaption></figure>

* Within the **snomedct** database the rights of this **newuser** are limited to the following actions.

<figure><img src="/files/lZ2Q6YWd3zrzTAQOoThm" alt=""><figcaption></figcaption></figure>

<a href="https://docs.google.com/forms/d/e/1FAIpQLScTmbZIf0UEQwYDkY27EEWBkaiYkHSbR0_9DmFrMLXoQLyL7Q/viewform?usp=pp_url&#x26;entry.1767247133=SQL+Guide&#x26;entry.670899847=A.5%20Using%20MySQL%20Workbench%20to%20Query%20SNOMED%20CT" class="button primary">Provide Feedback</a>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.snomed.org/snomed-ct-practical-guides/snomed-ct-sql-practical-guide/appendices/appendix-a-building-the-snomed-ct-example-database/a5-using-mysql-workbench-to-query-snomed-ct.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
