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

### Step 1. Connect to a remote Linux - the TiUP control machine

+ Click [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 instance

+ Connect to MySQL server node. 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: Thu Aug  1 11:58:47 2024 from 10.90.4.90
   [rocky@ip-10-90-1-235 ~]$
   ```

+ Connect to MySQL server as database user `root`.

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

   ```output
   mysql>
   ```

### Step 3. View the existing schema from MySQL

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

   ```sql
   SHOW DATABASES;
   ```

   ```output
   +--------------------+
   | Database           |
   +--------------------+
   | information_schema |
   | mysql              |
   | performance_schema |
   | sbtest             |
   | sys                |
   +--------------------+
   5 rows in set (0.01 sec)
   ```

   ```sql
   SHOW TABLES FROM sbtest;
   ```

   ```output
   +------------------+
   | Tables_in_sbtest |
   +------------------+
   | sbtest1          |
   | sbtest2          |
   | sbtest3          |
   | sbtest4          |
   | sbtest5          |
   | sbtest6          |
   +------------------+
   6 rows in set (0.00 sec)
   ```

+ Review the schema of table `sbtest.sbtest1`.

   ```sql
   DESC sbtest.sbtest1;
   ```

   ```output
   +-------+-----------+------+-----+---------+----------------+
   | Field | Type      | Null | Key | Default | Extra          |
   +-------+-----------+------+-----+---------+----------------+
   | id    | int       | NO   | PRI | NULL    | auto_increment |
   | k     | int       | NO   | MUL | 0       |                |
   | c     | char(120) | NO   |     |         |                |
   | pad   | char(60)  | NO   |     |         |                |
   +-------+-----------+------+-----+---------+----------------+
   4 rows in set (0.00 sec)
   ```

+ Review the row count of table `sbtest.sbtest1`. It should take you several seconds. (note that you are connecting to MySQL right now)

   ```sql
   SELECT COUNT(id) FROM sbtest.sbtest1;
   ```

   ```output
   +-----------+
   | COUNT(id) |
   +-----------+
   |  10000000 |
   +-----------+
   1 row in set (29.75 sec)
   ```

### Step 4. Understand the data volume in the source MySQL server

+ Execute `ANALYZE` command on database `sbtest`. Besides `sbtest1`, the database also contains `sbtest2`, `sbtest3`, `sbtest4`, `sbtest5`, and `sbtest6`.

   ```sql
   ANALYZE TABLE sbtest.sbtest1, sbtest.sbtest2, sbtest.sbtest3, sbtest.sbtest4, sbtest.sbtest5, sbtest.sbtest6;
   ```

   ```output
   +----------------+---------+----------+----------+
   | Table          | Op      | Msg_type | Msg_text |
   +----------------+---------+----------+----------+
   | sbtest.sbtest1 | analyze | status   | OK       |
   | sbtest.sbtest2 | analyze | status   | OK       |
   | sbtest.sbtest3 | analyze | status   | OK       |
   | sbtest.sbtest4 | analyze | status   | OK       |
   | sbtest.sbtest5 | analyze | status   | OK       |
   | sbtest.sbtest6 | analyze | status   | OK       |
   +----------------+---------+----------+----------+
   6 rows in set (34.08 sec)
   ```

+ Get the data volume of `sbtest` database, it should be around `13.43GB`.

   ```sql
   SELECT CONCAT(ROUND(SUM((data_length + index_length)/1024/1024/1024),2), 'GB') AS data
   FROM information_schema.tables
   WHERE table_schema='sbtest';
   ```

   ```output
   +---------+
   | data    |
   +---------+
   | 13.43GB |
   +---------+
   1 row in set (0.00 sec)
   ```

+ Exit to OS prompt.

   ```sql
   EXIT
   ```

   ```output
   bye
   ```

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