## 模块 1：连接到 MySQL Server 并运行查询以查看数据

### 步骤 1. 连接到远程 Linux

+ 点击这里 - [终端 1](ssh://monitor1-ssh#1) 打开一个新的终端，连接到为你的实践实验分配的虚拟机。

### 步骤 2. 连接到 MySQL server 节点

+ 从远程 Linux 连接到 MySQL server 节点，如果有提示，回答 `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 ~]$
   ```

### 步骤 3. 以数据库用户 `root` 连接到 MySQL server

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

   ```output
   mysql> 
   ```

### 步骤 4. 检查现有数据

+ 验证 `sbtest` 数据库中的表和数据已存在。

   ```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)
   ```

+ 查看 MySQL server 上 `sp500insight.stock_price_history` 表的行数。首次执行查询耗时超过 5 秒。

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

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

+ 退出到 MySQL server 节点。

   ```sql
   EXIT
   ```

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

+ 保持终端与 MySQL 服务器的连接（你看到的提示符应以 `[rocky@`），然后继续下一个练习。
