## Module 4: Exporting the Data from MySQL Using Dumpling

### Step 1. SSH to `PD3`

  ```bash
  ./ssh-to-pd3.sh
  ```

  ```output
  The authenticity of host '10.80.0.215 (10.80.0.215)' can't be established.
  ...

        __|  __|_  )
        _|  (     /   Amazon Linux 2 AMI
     ___|\___|___|

  https://aws.amazon.com/amazon-linux-2/
  ```

### Step 2. Start MySQL server instance

  ```bash
  sudo service mysqld start
  ```

### Step 3. Unzip the data on PD3

  ```bash
  unzip -u stage/tidb-admin-dataset-v2.zip -d stage/
  ```

### Step 4.. Login MySQL Server

  ```bash
  mysql -u root -p -h 127.0.0.1 -P 3306 -pq1w2e3R4_
  ```

### Step 5. Create a user for export task

  ```sql
  CREATE USER exp@'%' IDENTIFIED BY 'q1w2e3R4_';
  ```

  ```output
  mysql> CREATE USER exp@'%' IDENTIFIED BY 'q1w2e3R4_';
  Query OK, 0 rows affected (0.00 sec)
  ```

  ```sql
  GRANT ALL PRIVILEGES on *.* to exp@'%';
  ```

  ```output
  mysql> GRANT ALL PRIVILEGES on *.* to exp@'%';
  Query OK, 0 rows affected (0.00 sec)
  ```

### Step 6. Import data into MySQL

  ```sql
  SOURCE ./stage/TiDB-Administration-exercise-data-v2/exercise-dumpling/emp-schema-create.sql
  ```

  ```sql
  USE emp;
  ```

  ```output
  mysql> USE emp;
  Database changed
  ```

  ```sql
  SOURCE ./stage/TiDB-Administration-exercise-data-v2/exercise-dumpling/emp.dep-schema.sql
  SOURCE ./stage/TiDB-Administration-exercise-data-v2/exercise-dumpling/emp.dep.0000000010000.sql
  SOURCE ./stage/TiDB-Administration-exercise-data-v2/exercise-dumpling/emp.t-schema.sql
  SOURCE ./stage/TiDB-Administration-exercise-data-v2/exercise-dumpling/emp.t.0000000010000.sql
  SOURCE ./stage/TiDB-Administration-exercise-data-v2/exercise-dumpling/emp.emp-schema.sql
  SOURCE ./stage/TiDB-Administration-exercise-data-v2/exercise-dumpling/emp.emp.0000000010000.sql
  ```

  ```output
  ...
  Query OK, 16843 rows affected (0.14 sec)
  Records: 16843  Duplicates: 0  Warnings: 0

  Query OK, 12161 rows affected (0.10 sec)
  Records: 12161  Duplicates: 0  Warnings: 0
  ```

### Step 7. Review the tables in the `emp` database from MySQL

  ```sql
  SHOW TABLES;
  ```

  ```output
  mysql> SHOW TABLES;
  +---------------+
  | Tables_in_emp |
  +---------------+
  | dep           |
  | emp           |
  | t             |
  +---------------+
  3 rows in set (0.00 sec)
  ```

### Step 8. Return to `monitor1`

  ```sql
  EXIT
  ```

  ```output
  mysql> EXIT;
  Bye
  ```

  ```bash
  exit
  ```

  ```output
  logout
  Connection to 10.90.1.78 closed.
  ```

### Step 9. Export the `emp` database from MySQL

  ```bash
  tiup dumpling:v7.5.1 -uexp -P 3306 -h ${HOST_PD3_PRIVATE_IP} -pq1w2e3R4_ --filetype sql -t 8 -o /tmp/empmysql -r 200000 -F 256MiB -B emp
  ```

  ```output
  Release version: v7.5.1
  Git commit hash: 1a89decdb192cbdce6a7b0020d71128bc964d30f
  Git branch:      heads/refs/tags/v7.5.1
  Build timestamp: 2022-06-05 05:09:15Z
  Go version:      go version go1.18.2 linux/amd64

  [2022/11/08 15:18:17.316 +08:00] [INFO] [versions.go:55] ["Welcome to dumpling"] ["Release Version"=v7.5.1] ["Git Commit Hash"=1a89decdb192cbdce6a7b0020d71128bc964d30f] ["Git Branch"=heads/refs/tags/v7.5.1] ["Build timestamp"="2022-06-05 05:09:15"] ["Go Version"="go version go1.18.2 linux/amd64"]
  ...
  [2022/11/08 15:18:19.398 +08:00] [INFO] [main.go:80] ["dump data successfully, dumpling will exit now"]
  ```

### Step 10. View the contents in the output directory

  ```bash
  ls /tmp/empmysql
  ```

  ```output
  emp.dep.0000000010000.sql  emp.emp-schema.sql         emp.sal.0000000030000.sql  emp-schema-create.sql    metadata
  emp.dep-schema.sql         emp.sal.0000000010000.sql  emp.sal.0000000040000.sql  emp.t.0000000010000.sql
  emp.emp.0000000010000.sql  emp.sal.0000000020000.sql  emp.sal-schema.sql         emp.t-schema.sql
  ```
