## Module 1: Connect To A MySQL Server And Run Queries To Verify The Source Schema

### Step 1. Connect to a remote Linux

+ Click here - [Terminal 1](ssh://monitor1-ssh#1) to open a new terminal connected to the virtual machine assigned for your hands-on lab.

### Step 2. Connect to MySQL server node

+ Connect to the MySQL server node from the remote Linux, if prompted, answer `yes`.

   ```bash
   ssh -i /home/ec2-user/.ssh/pe-class-key-${LAB:REGION_NAME}.pem rocky@${HOST_MYSQL1_PRIVATE_IP}
   ```

   ```output
   Last login: Wed Oct  9 02:16:14 2024 from 10.90.4.225
   [rocky@ip-10-90-1-132 ~]$
   ```

### Step 3. Connect to MySQL server as database user `root`

   ```bash
   mysql -h localhost -P 3306 -u root -pq1w2e3R4_ --connect-expired-password
   ```

   ```output
   mysql> 
   ```

### Step 4. Check the existing schema

+ Verify the tables and data in `sbtest` database are already exist.

   ```sql
   SHOW DATABASES;
   ```

   ```output
   +--------------------+
   | Database           |
   +--------------------+
   | information_schema |
   | mysql              |
   | performance_schema |
   | sbtest             |
   | sp500insight       |
   | sys                |
   +--------------------+
   6 rows in set (0.00 sec)
   ```

   ```sql
   SHOW TABLES FROM sp500insight;
   ```

   ```output
   +------------------------+
   | Tables_in_sp500insight |
   +------------------------+
   | companies              |
   | index_compositions     |
   | index_price_history    |
   | indexes                |
   | stock_price_history    |
   | user_selected_stocks   |
   | users                  |
   +------------------------+
   7 rows in set (0.00 sec)
   ```

+ Review the row count of table `sp500insight.stock_price_history` on the MySQL server. It takes more than 5 seconds for the first execution.

   ```sql
   SELECT COUNT(*) FROM sp500insight.stock_price_history;
   ```

   ```output
   +----------+
   | COUNT(*) |
   +----------+
   |  1157000 |
   +----------+
   1 row in set (7.82 sec)
   ```

+ Exit to the MySQL server node OS prompt.

   ```sql
   EXIT
   ```

   ```output
   bye
   [rocky@ip-10-90-1-132 ~]$
   ```

+ Keep the terminal connected to MySQL server (the prompt you observe should be starting with `[rocky@`) and proceed to the next practice.
