lab_code: "demo_405"
title_en: Working with TiDB Cloud Using mysql-connector-python
title_ja: mysql-connector-python で TiDB Cloud を活用する
title_zh: 通过 mysql-connector-python 使用 TiDB Cloud
title_ko: mysql-connector-python을 사용하여 TiDB Cloud 사용
description_en: "In this lab, you will learn how to: Connect to, access and modify data in TiDB Cloud Starter cluster by Python code; Use prepared statements and batch inserts to improve the performance of your application; Use AUTO_RANDOM instead of AUTO_INCREMENT to avoid hotspots; Use online DDL to perform online schema changes; Use and compare pessimistic and optimistic modes for transaction concurrency control."
description_ja: "この演習では、次のことを学びます: Pythonコードを使用して、TiDB Cloud Starterクラスタに接続し、データにアクセスして変更する方法; プリペアドステートメントとバッチ挿入を使用して、アプリケーションのパフォーマンスを向上させる方法; ホットスポットを回避するためにAUTO_INCREMENTの代わりにAUTO_RANDOMを使用する方法; オンラインDDLを使用してオンラインスキーマ変更を実行する方法; トランザクションの同時実行制御のために悲観的モードと楽観的モードを使用して比較する方法。"
description_zh: 在本实验中，您将学习如何：通过 Python 代码连接、访问和修改 TiDB Cloud Starter 集群中的数据；使用预准备语句和批量插入来提高应用程序的性能；使用 AUTO_RANDOM 代替 AUTO_INCREMENT 以避免热点；使用在线 DDL 执行在线架构更改；使用并比较悲观和乐观模式进行事务并发控制。
description_ko: "이 실습에서는 다음을 배우게 됩니다: Python 코드를 사용하여 TiDB Cloud Starter 클러스터에 연결하고 데이터에 액세스하고 수정하는 방법; 애플리케이션의 성능을 향상시키기 위해 준비된 문장과 배치 삽입을 사용하는 방법; 화염 지점을 피하기 위해 AUTO_INCREMENT 대신 AUTO_RANDOM을 사용하는 방법; 온라인 DDL을 사용하여 온라인 스키마 변경을 수행하는 방법; 트랜잭션 동시성 제어를 위해 비관적 모드와 낙관적 모드를 사용하고 비교하는 방법。"
splash_image_en: https://lab-static.pingcap.com/quick-demo/demo_201_en.png
splash_image_ja: https://lab-static.pingcap.com/quick-demo/demo_201_en.png
splash_image_zh: https://lab-static.pingcap.com/quick-demo/demo_201_en.png
splash_image_ko: https://lab-static.pingcap.com/quick-demo/demo_201_en.png
lab_level: Beginner
category_en:
  - TiDB Cloud
  - Python
category_zh:
  - TiDB Cloud
  - Python
category_ja:
  - TiDB Cloud
  - Python
category_ko:
  - TiDB Cloud
  - Python
authors:
  - "Cheese Wong (CEG)"
delivery_type: Self-Paced
tidb_environments:
  - TiDB Cloud Starter
target_audience:
  - DevOps
  - Developer
regions:
  aws:
    - oregon
    - tokyo
    - singapore
    - frankfurt
  #alicloud:
  #  - singapore
# `credits` must be a positive integer
credits: 1
# `credit_redeemable` whether the lab is redeemable
credit_redeemable: true
# Whether the lab is only visible to employees
employee_only: false
# The estimated duration that user will spend on the lab, in minutes.
estimated_duration_minutes: 120

# `topology` section describes the virtual machine topology of the lab.
topology:
  # Corresponds to an EC2 role name from the CloudFormation template.
  # This MUST match a role name defined in the template's EC2 role section.
  - role: monitor
    # The number of nodes in the role
    # Each VM instance will be identified as `{role}{node_index}` within the lab system.
    # for example, if the role is `monitor` and the node_count is `2`, the virtual machines will be named as `monitor1` and `monitor2`.
    # the `monitor1` can be used in the `bootstrap` section.
    node_count: 1
    # Whether the virtual machine in this role accept web ssh connection
    # if `web_ssh` is true, there will be a web ssh button in the lab detail page for each virtual machine in this role.
    # for example, if the role is `monitor` and the node_count is `2`, the web ssh button will be named as `monitor1` and `monitor2`.
    web_ssh: false
    # The user name of the ssh connection
    ssh_user: ubuntu
    # Whether to enable HTTPS reverse proxy
    # if enable, lab will install the `caddy` to the virtual machine, and listen on 443 port to the public.
    # the `caddy` will forward the request to other internal servers, such as:
    #   - 3000 port of the vscode server
    https_reverse_proxy: true

# requirements section describes the requirements of the lab.
requirements:
  # CloudStack will use IaC templates (`cloudformation.json` for AWS, `alicloud_ros.json` for Alicloud) to create the virtual machines and network resources.
  - type: "CloudStack"
    # TiDBServerlessCluster will create the TiDB Cloud Serverless cluster for the lab.
    # it supports following two types of TiDB Cloud Serverless cluster:
    #   - Sandbox, provided by TiDB Labs the cluster will be deleted after the lab is finished.
    #   - User-managed, provided by the user via TiDB Cloud OAuth2, the cluster will not be deleted after the lab is finished.
  - type: "TiDBServerlessCluster"

# bootstrap section describes the bootstrap scripts of the lab.
# this section will be executed after the requirements are satisfied.
bootstrap:
  # The name of the bootstrap script, it should be human readable.
  - name: "prepare monitor"
    # ShellScript will execute the shell script on the virtual machine.
    type: "ShellScript"
    # The target VM instance(s) for this script, using the `{role}{node_index}` identifier.
    # If there are multiple VMs in the target list, the script will be executed one by one, it's not parallel.
    target:
      - monitor1
    # The script to be executed, it should be the path to the script.
    script: ./scripts/prepare-monitor.sh

features:
  enable_content_explain: false
