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.
Exercise
Answer
    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
    Open up the Explorer View (Cmd/Ctrl + Shift + E)
    Notice that there is a MySQL view section
    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
    Right-click the "mysql" connection and select "New Query"
    Create a database called "Lamp"
1
CREATE DATABASE Lamp;
Copied!
    Execute the query by opening the Command Palette (Cmd/Ctrl + Shift + P) and selecting "MySQL: Run MySQL Query"
    Create a new table in the MySQL Database called "Colors"
1
USE Lamp;
2
3
CREATE TABLE IF NOT EXISTS Colors (
4
color_id INT AUTO_INCREMENT,
5
color VARCHAR(255) NOT NULL,
6
PRIMARY KEY (color_id)
7
) ENGINE=INNODB;
Copied!
    Press Ctrl + Opt/Alt + E to execute the query
    Right-click the MySQL connection and select "Refresh"
    Notice there is now a "Lamp" database with a "Colors" table
    Insert a record into the database
1
USE Lamp;
2
3
INSERT INTO Colors (color) VALUES("Blue")
Copied!
    Execute the query with Ctrl + Opt/Alt + E
    Select everything from the "Colors" table
1
USE Lamp;
2
3
SELECT * FROM Colors
Copied!
    View the results
Last modified 2yr ago
Copy link