## Module 3: Make Some Changes From The Source MySQL

### Step 1. Connect to the TiUP control machine, and then the MySQL server

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

+ Connect to MySQL server node.

   ```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 with a database session.

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

   ```output
   mysql>
   ```

### Step 2. Execute UPDATE from MySQL

+ On [Terminal 2](ssh://monitor1-ssh#2) (the MySQL side), set column `c` to `Changed on MySQL` for a specific row.

   ```sql
   SELECT * FROM sbtest.sbtest1 WHERE id=1;
   UPDATE sbtest.sbtest1 SET c='Changed on MySQL' WHERE id=1;
   SELECT * FROM sbtest.sbtest1 WHERE id=1;
   ```

   ```output
   mysql> SELECT * FROM sbtest.sbtest1 WHERE id=1;
   +----+---------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
   | id | k       | c                                                                                                                       | pad                                                         |
   +----+---------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
   |  1 | 5014614 | 68487932199-96439406143-93774651418-41631865787-96406072701-20604855487-25459966574-28203206787-41238978918-19503783441 | 22195207048-70116052123-74140395089-76317954521-98694025897 |
   +----+---------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+
   1 row in set (0.00 sec)

   mysql> UPDATE sbtest.sbtest1 SET c='Changed on MySQL' WHERE id=1;
   Query OK, 1 row affected (0.00 sec)
   Rows matched: 1  Changed: 1  Warnings: 0

   mysql> SELECT * FROM sbtest.sbtest1 WHERE id=1;
   +----+---------+------------------+-------------------------------------------------------------+
   | id | k       | c                | pad                                                         |
   +----+---------+------------------+-------------------------------------------------------------+
   |  1 | 5014614 | Changed on MySQL | 22195207048-70116052123-74140395089-76317954521-98694025897 |
   +----+---------+------------------+-------------------------------------------------------------+
   1 row in set (0.00 sec)
   ```

### Step 3. Connect to the TiUP control machine, and then the TiDB instance

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

+ Connect to TiDB cluster.

   ```bash
   export MYSQL_PS1="tidb:db1> "
   mysql -h ${HOST_DB1_PRIVATE_IP} -P 4000 -u root
   ```

   ```output
   tidb:db1>
   ```

### Step 4. Obverse the UPDATE operation result from TiDB

+ On [Terminal 3](ssh://monitor1-ssh#3) (the TiDB side), observe the `UPDATE` result from TiDB side, the change had been already synced from MySQL.

   ```sql
   SELECT * FROM sbtest.sbtest1 WHERE id=1;
   ```

   ```output
   tidb:db1> SELECT * FROM sbtest.sbtest1 WHERE id=1;
   +----+---------+------------------+-------------------------------------------------------------+
   | id | k       | c                | pad                                                         |
   +----+---------+------------------+-------------------------------------------------------------+
   |  1 | 5014614 | Changed on MySQL | 22195207048-70116052123-74140395089-76317954521-98694025897 |
   +----+---------+------------------+-------------------------------------------------------------+
   1 row in set (0.01 sec)
   ```

### Step 5. Execute the INSERT operation in MySQL

+ On [Terminal 2](ssh://monitor1-ssh#2) (the MySQL side), insert a new row.

   ```sql
   INSERT INTO sbtest.sbtest1 (k, c, pad) VALUES (102, 'Insert on MySQL', 'Insert on MySQL');
   SELECT * FROM sbtest.sbtest1 WHERE k=102;
   ```

   ```output
   mysql> INSERT INTO sbtest.sbtest1 (k, c, pad) VALUES (102, 'Insert on MySQL', 'Insert on MySQL');
   Query OK, 1 row affected (0.00 sec)

   mysql> SELECT * FROM sbtest.sbtest1 WHERE k=102;
   +----------+-----+-----------------+-----------------+
   | id       | k   | c               | pad             |
   +----------+-----+-----------------+-----------------+
   | 10000002 | 102 | Insert on MySQL | Insert on MySQL |
   +----------+-----+-----------------+-----------------+
   1 row in set (0.00 sec)
   ```

### Step 6. Observe the INSERT operation result from TiDB

+ On [Terminal 3](ssh://monitor1-ssh#3) (the TIDB side), observe the `INSERT` result from TiDB side, the change had been already synced from MySQL.

   ```sql
   SELECT * FROM sbtest.sbtest1 WHERE k=102;
   ```

   ```output
   tidb:db1> SELECT * from sbtest.sbtest1 where k=102;
   +----------+-----+-----------------+-----------------+
   | id       | k   | c               | pad             |
   +----------+-----+-----------------+-----------------+
   | 10000002 | 102 | Insert on MySQL | Insert on MySQL |
   +----------+-----+-----------------+-----------------+
   1 row in set (0.00 sec)
   ```

+ If time allows, try more modifications from MySQL side and observe the result from TiDB side.
