# Working with MySQL

MySQL, SQL Server and others are all common transactional database systems. VS Code has extensions for most of these. In this exercise, you'll connect to a MySQL database, execute queries and view the results in VS Code.

{% tabs %}
{% tab title="Exercise" %}

* Connect to the "mysql" container with the MySQL extension
  * username: root
  * password: example
* Execute the queries in the "mysql.sql" file
* View the query results
  {% endtab %}

{% tab title="Answer" %}

* Open up the Explorer View (**Cmd/Ctrl + Shift + E**)
* Notice that there is a MySQL view section

![](/files/-Lm7ClkB-dIpY05Dr89r)

* Click the "+" button to create a new connection
  * Server Name: mysql
  * User name: root
  * Password: example
  * Port: Default
  * SSL: Leave Empty
* VS Code will now be connected to MySQL

![](/files/-Lm7D8vx-RYibhqApc7b)

* Right-click the "mysql" connection and select "New Query"

![](/files/-Lm7DIyBxBW6MVOlSIvE)

* Create a database called "Lamp"

```
CREATE DATABASE Lamp;
```

* Execute the query by opening the Command Palette (**Cmd/Ctrl + Shift + P**) and selecting "MySQL: Run MySQL Query"

![](/files/-Lm7DuJHA2THA72idshQ)

* Create a new table in the MySQL Database called "Colors"

```
USE Lamp;

CREATE TABLE IF NOT EXISTS Colors (
    color_id INT AUTO_INCREMENT,
    color VARCHAR(255) NOT NULL,
    PRIMARY KEY (color_id)
)  ENGINE=INNODB;
```

* Press **Ctrl + Opt/Alt + E** to execute the query
* Right-click the MySQL connection and select "Refresh"

![](/files/-Lm7ESasOLTw9guW_VQE)

* Notice there is now a "Lamp" database with a "Colors" table
* Insert a record into the database

```
USE Lamp;

INSERT INTO Colors (color) VALUES("Blue")
```

* Execute the query with **Ctrl + Opt/Alt + E**
* Select everything from the "Colors" table

```
USE Lamp;

SELECT * FROM Colors
```

* View the results

![](/files/-Lm7FJlHBgSxRc574OP1)
{% endtab %}
{% endtabs %}


---

# Agent Instructions: 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:

```
GET https://burkeholland.gitbook.io/vs-code-can-do-that/exercise-7-working-with-data/working-with-mysql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
