### Start task command output example Source: https://github.com/pingcap/docs/blob/master/tidb-cloud/migrate-sql-shards.md Example JSON response from a successful start-task command showing task initialization status for multiple MySQL replica sources. ```json { "result": true, "msg": "", "sources": [ { "result": true, "msg": "", "source": "mysql-replica-01", "worker": "dm-192.168.11.111-9262" }, { "result": true, "msg": "", "source": "mysql-replica-02", "worker": "dm-192.168.11.112-9262" } ], "checkResult": "" } ``` -------------------------------- ### DELETE statement setup and example Source: https://github.com/pingcap/docs/blob/master/sql-statements/sql-statement-delete.md Complete example showing table creation, data insertion, and deletion. Demonstrates the full workflow of creating a table, inserting rows, and deleting a specific row. ```sql CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, c1 INT NOT NULL); ``` ```sql INSERT INTO t1 (c1) VALUES (1),(2),(3),(4),(5); ``` ```sql SELECT * FROM t1; ``` -------------------------------- ### start-task command usage example Source: https://github.com/pingcap/docs/blob/master/dm/dm-create-task.md Start a data migration task by specifying a MySQL source and task configuration file. ```bash start-task [ -s "mysql-replica-01"] ./task.yaml ``` -------------------------------- ### Initialize Netlify Project for Continuous Deployment Source: https://github.com/pingcap/docs/blob/master/tidb-cloud/integrate-tidbcloud-with-netlify.md Start the automatic setup to connect your repository, creating a deploy key and webhook for continuous deployment. ```shell netlify init ``` -------------------------------- ### Create and activate a Python virtual environment Source: https://github.com/pingcap/docs/blob/master/ai/integrations/vector-search-integrate-with-peewee.md Navigates to the peewee quickstart example directory and creates and activates a Python virtual environment. ```bash cd tidb-vector-python/examples/orm-peewee-quickstart python3 -m venv .venv source .venv/bin/activate ``` -------------------------------- ### Example: Configure MySQL Client PATH in Git Bash (Windows) Source: https://github.com/pingcap/docs/blob/master/develop/dev-guide-proxysql-integration.md An example demonstrating how to add a specific MySQL client bin directory to the PATH in Git Bash on Windows for a typical installation. ```bash echo 'export PATH="/c/Program Files (x86)/mysql-8.0.31-winx64/bin":$PATH' >>~/.bash_profile source ~/.bash_profile ``` -------------------------------- ### Explain Query with Full Table Scan Source: https://github.com/pingcap/docs/blob/master/system-variables.md This example shows the query plan for a selection on a table, demonstrating a full table scan when `tidb_opt_prefer_range_scan` is not active or statistics are missing. ```sql explain select * from t where age=5; ``` -------------------------------- ### Create and Use a New Database Source: https://github.com/pingcap/docs/blob/master/sql-statements/sql-statement-create-database.md This example demonstrates how to create a new database, switch to it, create a table within it, and then list the tables to confirm creation. ```sql mysql> CREATE DATABASE mynewdatabase; Query OK, 0 rows affected (0.09 sec) mysql> USE mynewdatabase; Database changed mysql> CREATE TABLE t1 (a int); Query OK, 0 rows affected (0.11 sec) mysql> SHOW TABLES; +-------------------------+ | Tables_in_mynewdatabase | +-------------------------+ | t1 | +-------------------------+ 1 row in set (0.00 sec) ``` -------------------------------- ### Clone PyMySQL sample application repository Source: https://github.com/pingcap/docs/blob/master/develop/dev-guide-sample-application-python-pymysql.md Clone the TiDB Python PyMySQL quickstart sample repository to get started with the example application. ```shell git clone https://github.com/tidb-samples/tidb-python-pymysql-quickstart.git cd tidb-python-pymysql-quickstart ``` -------------------------------- ### Demonstrate AUTO_INCREMENT with Offset and Increment in SQL Source: https://github.com/pingcap/docs/blob/master/system-variables.md This SQL example shows how to set `auto_increment_offset` and `auto_increment_increment` to customize the sequence of `AUTO_INCREMENT` values in a table. ```SQL mysql> CREATE TABLE t1 (a int not null primary key auto_increment); Query OK, 0 rows affected (0.10 sec) mysql> set auto_increment_offset=1; Query OK, 0 rows affected (0.00 sec) mysql> set auto_increment_increment=3; Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO t1 VALUES (),(),(),(); Query OK, 4 rows affected (0.04 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM t1; +----+ | a | +----+ | 1 | | 4 | | 7 | | 10 | +----+ 4 rows in set (0.00 sec) ``` -------------------------------- ### Clone the tidb-vector-python repository Source: https://github.com/pingcap/docs/blob/master/ai/integrations/vector-search-integrate-with-django-orm.md Clone the example repository to your local machine to get started with the tutorial. ```shell git clone https://github.com/pingcap/tidb-vector-python.git ``` -------------------------------- ### Setup Table, Insert Data, and Initial Query Plan Source: https://github.com/pingcap/docs/blob/master/sql-statements/sql-statement-show-bindings.md This snippet creates a table, populates it with sample data, analyzes the table statistics, and then shows the initial execution plan for a query before any SQL binding is applied. ```sql mysql> CREATE TABLE t1 ( id INT NOT NULL PRIMARY KEY auto_increment, b INT NOT NULL, pad VARBINARY(255), INDEX(b) ); Query OK, 0 rows affected (0.07 sec) mysql> INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(255) FROM dual; Query OK, 1 row affected (0.01 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(255) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 100000; Query OK, 1 row affected (0.00 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(255) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 100000; Query OK, 8 rows affected (0.00 sec) Records: 8 Duplicates: 0 Warnings: 0 mysql> INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(255) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 100000; Query OK, 1000 rows affected (0.04 sec) Records: 1000 Duplicates: 0 Warnings: 0 mysql> INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(255) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 100000; Query OK, 100000 rows affected (1.74 sec) Records: 100000 Duplicates: 0 Warnings: 0 mysql> INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(255) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 100000; Query OK, 100000 rows affected (2.15 sec) Records: 100000 Duplicates: 0 Warnings: 0 mysql> INSERT INTO t1 SELECT NULL, FLOOR(RAND()*1000), RANDOM_BYTES(255) FROM t1 a JOIN t1 b JOIN t1 c LIMIT 100000; Query OK, 100000 rows affected (2.64 sec) Records: 100000 Duplicates: 0 Warnings: 0 mysql> SELECT SLEEP(1); +----------+ | SLEEP(1) | +----------+ | 0 | +----------+ 1 row in set (1.00 sec) mysql> ANALYZE TABLE t1; Query OK, 0 rows affected (1.33 sec) mysql> EXPLAIN ANALYZE SELECT * FROM t1 WHERE b = 123; +------------------------------- ---------+---------+-----------+----------------------+---------------------------------------------------------------------------+-----------------------------------+----------------+------+ | id | estRows | actRows | task | access object | execution info | operator info | memory | disk | +------------------------------- ---------+---------+-----------+----------------------+---------------------------------------------------------------------------+-----------------------------------+----------------+------+ | IndexLookUp_10 | 583.00 | 297 | root | | time:10.545072ms, loops:2, rpc num: 1, rpc time:398.359µs, proc keys:297 | | 109.1484375 KB | N/A | | ├─IndexRangeScan_8(Build) | 583.00 | 297 | cop[tikv] | table:t1, index:b(b) | time:0s, loops:4 | range:[123,123], keep order:false | N/A | N/A | | └─TableRowIDScan_9(Probe) | 583.00 | 297 | cop[tikv] | table:t1 | time:12ms, loops:4 | keep order:false | N/A | N/A | +------------------------------- ---------+---------+-----------+----------------------+---------------------------------------------------------------------------+-----------------------------------+----------------+------+ 3 rows in set (0.02 sec) ``` -------------------------------- ### Demonstrate `tidb_opt_ordering_index_selectivity_threshold` effect on index selection Source: https://github.com/pingcap/docs/blob/master/system-variables.md This example shows how setting `tidb_opt_ordering_index_selectivity_threshold` changes the optimizer's index selection for queries with `ORDER BY`, `LIMIT`, and filter conditions. The first `EXPLAIN` shows default behavior, and the second shows the effect after setting the threshold. ```sql > EXPLAIN SELECT * FROM t WHERE b <= 9000 ORDER BY a LIMIT 1; +-----------------------------------+---------+-----------+----------------------+--------------------+ | id | estRows | task | access object | operator info | +-----------------------------------+---------+-----------+----------------------+--------------------+ | Limit_12 | 1.00 | root | | offset:0, count:1 | | └─Projection_25 | 1.00 | root | | test.t.a, test.t.b | | └─IndexLookUp_24 | 1.00 | root | | | | ├─IndexFullScan_21(Build) | 114.30 | cop[tikv] | table:t, index:ia(a) | keep order:true | | └─Selection_23(Probe) | 1.00 | cop[tikv] | | le(test.t.b, 9000) | | └─TableRowIDScan_22 | 114.30 | cop[tikv] | table:t | keep order:false | +-----------------------------------+---------+-----------+----------------------+--------------------+ ``` ```sql > SET SESSION tidb_opt_ordering_index_selectivity_threshold = 0.01; ``` ```sql > EXPLAIN SELECT * FROM t WHERE b <= 9000 ORDER BY a LIMIT 1; +----------------------------------+---------+-----------+----------------------+-------------------------------------+ | id | estRows | task | access object | operator info | +----------------------------------+---------+-----------+----------------------+-------------------------------------+ | TopN_9 | 1.00 | root | | test.t.a, offset:0, count:1 | | └─IndexLookUp_20 | 1.00 | root | | | | ├─IndexRangeScan_17(Build) | 8748.62 | cop[tikv] | table:t, index:ib(b) | range:[-inf,9000], keep order:false | | └─TopN_19(Probe) | 1.00 | cop[tikv] | | test.t.a, offset:0, count:1 | | └─TableRowIDScan_18 | 8748.62 | cop[tikv] | table:t | keep order:false | +----------------------------------+---------+-----------+----------------------+-------------------------------------+ ``` -------------------------------- ### Clone the sample application repository Source: https://github.com/pingcap/docs/blob/master/develop/dev-guide-sample-application-golang-sql-driver.md Use these shell commands to clone the quickstart repository and navigate into its directory. ```shell git clone https://github.com/tidb-samples/tidb-golang-sql-driver-quickstart.git cd tidb-golang-sql-driver-quickstart ``` -------------------------------- ### Clone peewee sample application repository Source: https://github.com/pingcap/docs/blob/master/develop/dev-guide-sample-application-python-peewee.md Clone the TiDB Python peewee quickstart sample repository to get started with the sample application. ```shell git clone https://github.com/tidb-samples/tidb-python-peewee-quickstart.git cd tidb-python-peewee-quickstart ``` -------------------------------- ### Demonstrating tidb_opt_distinct_agg_push_down in SQL Source: https://github.com/pingcap/docs/blob/master/system-variables.md This example illustrates how enabling the `tidb_opt_distinct_agg_push_down` variable changes the execution plan for `COUNT(DISTINCT)` queries, pushing the distinct aggregation to the Coprocessor. ```sql mysql> desc select count(distinct a) from test.t; +-------------------------+----------+-----------+---------------+------------------------------------------+ | id | estRows | task | access object | operator info | +-------------------------+----------+-----------+---------------+------------------------------------------+ | StreamAgg_6 | 1.00 | root | | funcs:count(distinct test.t.a)->Column#4 | | └─TableReader_10 | 10000.00 | root | | data:TableFullScan_9 | | └─TableFullScan_9 | 10000.00 | cop[tikv] | table:t | keep order:false, stats:pseudo | +-------------------------+----------+-----------+---------------+------------------------------------------+ 3 rows in set (0.01 sec) mysql> set session tidb_opt_distinct_agg_push_down = 1; Query OK, 0 rows affected (0.00 sec) mysql> desc select count(distinct a) from test.t; +---------------------------+----------+-----------+---------------+------------------------------------------+ | id | estRows | task | access object | operator info | +---------------------------+----------+-----------+---------------+------------------------------------------+ | HashAgg_8 | 1.00 | root | | funcs:count(distinct test.t.a)->Column#3 | | └─TableReader_9 | 1.00 | root | | data:HashAgg_5 | | └─HashAgg_5 | 1.00 | cop[tikv] | | group by:test.t.a, | | └─TableFullScan_7 | 10000.00 | cop[tikv] | table:t | keep order:false, stats:pseudo | +---------------------------+----------+-----------+---------------+------------------------------------------+ 4 rows in set (0.00 sec) ``` -------------------------------- ### Clone TiDB AppFlow Integration Repository Source: https://github.com/pingcap/docs/blob/master/develop/dev-guide-aws-appflow-integration.md Clone the integration example code repository from GitHub to get started with TiDB and Amazon AppFlow integration. ```bash git clone https://github.com/pingcap-inc/tidb-appflow-integration ``` -------------------------------- ### Prepare Sample Data with TiUP Demo Source: https://github.com/pingcap/docs/blob/master/develop/dev-guide-optimize-sql.md Run this command to set up the `bookshop` sample data for performance tuning exercises. It populates the database with a specified number of books. ```shell tiup demo bookshop prepare --host 127.0.0.1 --port 4000 --books 1000000 ``` -------------------------------- ### Kafka Broker Startup Script Source: https://github.com/pingcap/docs/blob/master/tidb-cloud/setup-self-hosted-kafka-private-service-connect.md Bash script to start a Kafka broker with Java environment setup. Sets JAVA_HOME to a bundled JDK installation within the script directory. ```shell #!/bin/bash # Get the directory of the current script SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Set JAVA_HOME to the Java installation within the script directory export JAVA_HOME="$SCRIPT_DIR/jdk-22.0.2" ``` -------------------------------- ### Create Partitioned Table and Query PARTITIONS Source: https://github.com/pingcap/docs/blob/master/information-schema/information-schema-partitions.md This example demonstrates creating a hash-partitioned table and then querying the `PARTITIONS` table to retrieve its partition details. ```sql CREATE TABLE test.t1 (id INT NOT NULL PRIMARY KEY) PARTITION BY HASH (id) PARTITIONS 2; SELECT * FROM PARTITIONS WHERE table_schema='test' AND table_name='t1'\G ``` -------------------------------- ### Start n8n with npm Source: https://github.com/pingcap/docs/blob/master/tidb-cloud/integrate-tidbcloud-with-n8n.md Install and start n8n using npx after installing Node.js on your workspace. ```shell npx n8n ``` -------------------------------- ### Example: List all available user profiles Source: https://github.com/pingcap/docs/blob/master/tidb-cloud/ticloud-config-list.md Demonstrates how to list all available user profiles without any additional flags. ```shell ticloud config list ``` -------------------------------- ### Safe start output example Source: https://github.com/pingcap/docs/blob/master/production-deployment-using-tiup.md Example output from a successful safe start operation showing the auto-generated root password that is displayed only once. ```shell Started cluster `tidb-test` successfully. The root password of TiDB database has been changed. The new password is: 'y_+3Hwp=*AWz8971s6'. Copy and record it to somewhere safe, it is only displayed once, and will not be stored. The generated password can NOT be got again in future. ``` -------------------------------- ### Convert Subquery to Join and Aggregation in SQL Source: https://github.com/pingcap/docs/blob/master/system-variables.md This variable enables an optimization rule that converts `IN` subqueries into join and aggregation operations for improved performance. The examples show the original subquery and its converted forms. ```SQL select * from t where t.a in (select aa from t1); ``` ```SQL select t.* from t, (select aa from t1 group by aa) tmp_t where t.a = tmp_t.aa; ``` ```SQL select t.* from t, t1 where t.a=t1.aa; ``` -------------------------------- ### Install and Enable NTP Service on CentOS 7 Source: https://github.com/pingcap/docs/blob/master/check-before-deployment.md Run this command to manually install `ntp` and `ntpdate`, start the `ntpd` service, and enable it to start on boot for CentOS 7 systems. ```bash sudo yum install ntp ntpdate && \ sudo systemctl start ntpd.service && \ sudo systemctl enable ntpd.service ``` -------------------------------- ### Create project directory Source: https://github.com/pingcap/docs/blob/master/develop/serverless-driver-kysely-example.md Initializes a new project directory named 'kysely-node-example' and navigates into it. ```bash mkdir kysely-node-example cd kysely-node-example ``` -------------------------------- ### Create Starter instance with spending limit Source: https://github.com/pingcap/docs/blob/master/tidb-cloud/ticloud-cluster-create.md Creates a Starter instance with a monthly spending limit specified in USD cents. ```shell ticloud serverless create --display-name --region --spending-limit-monthly ``` -------------------------------- ### Start a Specific DM Cluster Source: https://github.com/pingcap/docs/blob/master/dm/deploy-a-dm-cluster-using-tiup-offline.md Use this command to start the specified DM cluster, for example, 'dm-test'. A successful start is confirmed by the output message 'Started cluster `dm-test` successfully'. ```shell tiup dm start dm-test ``` -------------------------------- ### Example MySQL Client Version Output (Linux) Source: https://github.com/pingcap/docs/blob/master/develop/dev-guide-build-cluster-in-cloud.md This is an example of the expected output when verifying the MySQL client installation on Linux. ```shell mysql Ver 15.1 Distrib 5.5.68-MariaDB, for Linux (x86_64) using readline 5.1 ``` -------------------------------- ### Create and activate a Python virtual environment Source: https://github.com/pingcap/docs/blob/master/ai/integrations/vector-search-integrate-with-sqlalchemy.md Navigate to the example directory and set up a new Python virtual environment. ```bash cd tidb-vector-python/examples/orm-sqlalchemy-quickstart python3 -m venv .venv source .venv/bin/activate ``` -------------------------------- ### Create table and insert sample data with SQL Source: https://github.com/pingcap/docs/blob/master/tidb-cloud/import-with-mysql-cli-serverless.md SQL file example that creates a products table and inserts sample data. Use this as a template for preparing your data import. ```sql -- Create a table in your TiDB database CREATE TABLE products ( product_id INT PRIMARY KEY, product_name VARCHAR(255), price DECIMAL(10, 2) ); -- Insert sample data into the table INSERT INTO products (product_id, product_name, price) VALUES (1, 'Laptop', 999.99), (2, 'Smartphone', 499.99), (3, 'Tablet', 299.99); ``` -------------------------------- ### Example MySQL Client Version Output (macOS) Source: https://github.com/pingcap/docs/blob/master/develop/dev-guide-build-cluster-in-cloud.md This is an example of the expected output when verifying the MySQL client installation on macOS. ```shell mysql Ver 8.0.28 for macos12.0 on arm64 (Homebrew) ``` -------------------------------- ### Install multiple TiUP components Source: https://github.com/pingcap/docs/blob/master/migration-tools.md This command allows you to install several TiUP components simultaneously, for example, 'dm' and 'tidb-lightning'. ```shell tiup install dm tidb-lightning ``` -------------------------------- ### SQL for Table Creation, Data Insertion, and EXPLAIN Query Source: https://github.com/pingcap/docs/blob/master/explain-overview.md Use these SQL commands to set up a sample table, insert data, and then apply EXPLAIN to analyze the execution plan of a SELECT query. ```sql CREATE TABLE t (id INT NOT NULL PRIMARY KEY auto_increment, a INT NOT NULL, pad1 VARCHAR(255), INDEX(a)); INSERT INTO t VALUES (1, 1, 'aaa'),(2,2, 'bbb'); EXPLAIN SELECT * FROM t WHERE a = 1; ``` -------------------------------- ### Example SHOW CREATE TABLE Output Source: https://github.com/pingcap/docs/blob/master/partitioned-table.md Verbatim output showing the structure of the 'example' table after partition modifications, including partition names and comments. ```console *************************** 1. row *************************** Table: example Create Table: CREATE TABLE `example` ( `id` int NOT NULL, `data` varchar(1024) DEFAULT NULL, PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin PARTITION BY HASH (`id`) (PARTITION `p0`, PARTITION `p1`, PARTITION `p2`, PARTITION `pExample4` COMMENT 'not p3, but pExample4 instead') 1 row in set (0.01 sec) ``` -------------------------------- ### Install TiProxy Control using TiUP Source: https://github.com/pingcap/docs/blob/master/tiproxy/tiproxy-command-line-flags.md Use TiUP to download and install the binary programs for TiProxy and TiProxy Control. This example also shows how to locate the installed `tiproxyctl` binary. ```shell tiup install tiproxy # download https://tiup-mirrors.pingcap.com/tiproxy-v1.3.0-linux-amd64.tar.gz 22.51 MiB / 22.51 MiB 100.00% 13.99 MiB/s ls `tiup --binary tiproxy`ctl # /root/.tiup/components/tiproxy/v1.3.0/tiproxyctl ``` -------------------------------- ### Netlify Project Initialization Output Example Source: https://github.com/pingcap/docs/blob/master/tidb-cloud/integrate-tidbcloud-with-netlify.md Illustrative output from netlify init showing site creation, GitHub authorization, and build command configuration. ```shell Adding local .netlify folder to .gitignore file... ? What would you like to do? + Create & configure a new site ? Team: your_username’s team ? Site name (leave blank for a random name; you can change it later): Site Created Admin URL: https://app.netlify.com/sites/mellow-crepe-e2ca2b URL: https://mellow-crepe-e2ca2b.netlify.app Site ID: b23d1359-1059-49ed-9d08-ed5dba8e83a2 Linked to mellow-crepe-e2ca2b ? Netlify CLI needs access to your GitHub account to configure Webhooks and Deploy Keys. What would you like to do? Authorize with GitHub through app.netlify.com Configuring Next.js runtime... ? Your build command (hugo build/yarn run build/etc): npm run netlify-build ? Directory to deploy (blank for current dir): .next Adding deploy key to repository... (node:36812) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time (Use `node --trace-warnings ...` to show where the warning was created) Deploy key added! Creating Netlify GitHub Notification Hooks... Netlify Notification Hooks configured! Success! Netlify CI/CD Configured! This site is now configured to automatically deploy from github branches & pull requests Next steps: git push Push to your git repository to trigger new site builds netlify open Open the Netlify admin URL of your site ``` -------------------------------- ### Example of comments in a table filter file Source: https://github.com/pingcap/docs/blob/master/table-filter.md Lines starting with `#` are treated as comments and ignored. A `#` not at the start of a line is considered a syntax error. ```text # this line is a comment db.table # but this part is not comment and may cause error ``` -------------------------------- ### TiUP Installation Success Output Source: https://github.com/pingcap/docs/blob/master/quick-start-with-tidb.md Example output displayed after a successful TiUP installation, indicating the shell profile path that needs to be sourced. ```log Successfully set mirror to https://tiup-mirrors.pingcap.com Detected shell: bash Shell profile: /home/user/.bashrc /home/user/.bashrc has been modified to add tiup to PATH open a new terminal or source /home/user/.bashrc to use it Installed path: /home/user/.tiup/bin/tiup =============================================== Have a try: tiup playground =============================================== ``` -------------------------------- ### Install Prerequisites on CentOS Source: https://github.com/pingcap/docs/blob/master/develop/dev-guide-proxysql-integration.md Install Docker, Git, Python, Docker Compose, and MySQL client on CentOS, then start the Docker service to prepare the environment. ```bash curl -fsSL https://get.docker.com | bash -s docker yum install -y git python39 docker-ce docker-ce-cli containerd.io docker-compose-plugin mysql systemctl start docker ``` -------------------------------- ### Install GORM and MySQL Driver for Golang Source: https://github.com/pingcap/docs/blob/master/develop/dev-guide-choose-driver-or-orm.md Uses `go get` to install the GORM ORM framework and its MySQL driver for use in a Golang application. ```shell go get -u gorm.io/gorm go get -u gorm.io/driver/mysql ``` -------------------------------- ### Create Sample Data (Docker MySQL) Source: https://github.com/pingcap/docs/blob/master/dm/quick-start-with-dm.md Creates a 'hello' database, a 'hello_tidb' table, inserts sample data, and selects it for verification. ```sql CREATE DATABASE hello; USE hello; CREATE TABLE hello_tidb ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) ); INSERT INTO hello_tidb (name) VALUES ('Hello World'); SELECT * FROM hello_tidb; ``` -------------------------------- ### Start Continuous Data Validation with dmctl Source: https://github.com/pingcap/docs/blob/master/dm/dm-continuous-data-validation.md Example command to start continuous data validation for a specific DM task (`my_dm_task`) using `dmctl`, specifying the master address, start time, and validation mode. ```shell dmctl --master-addr=127.0.0.1:8261 validation start --start-time 2021-10-21T00:01:00 --mode full my_dm_task ``` -------------------------------- ### Start Kafka Broker Script Source: https://github.com/pingcap/docs/blob/master/tidb-cloud/setup-azure-self-hosted-kafka-private-link-service.md Shell script to start Kafka brokers with proper environment setup. Sets JAVA_HOME, Kafka directories, and includes logic to kill any existing Kafka processes before starting new ones. ```shell SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" export JAVA_HOME="$SCRIPT_DIR/jdk-22.0.2" KAFKA_DIR="$SCRIPT_DIR/kafka_2.13-3.7.1/bin" KAFKA_STORAGE_CMD=$KAFKA_DIR/kafka-storage.sh KAFKA_START_CMD=$KAFKA_DIR/kafka-server-start.sh KAFKA_DATA_DIR=$SCRIPT_DIR/data KAFKA_LOG_DIR=$SCRIPT_DIR/log KAFKA_CONFIG_DIR=$SCRIPT_DIR/config KAFKA_PIDS=$(ps aux | grep 'kafka.Kafka' | grep -v grep | awk '{print $2}') if [ -z "$KAFKA_PIDS" ]; then echo "No Kafka processes are running." else echo "Killing Kafka processes with PIDs: $KAFKA_PIDS" for PID in $KAFKA_PIDS; do kill -9 $PID echo "Killed Kafka process with PID: $PID" done ``` -------------------------------- ### SQL Setup and EXPLAIN with Default Subquery Pre-execution Source: https://github.com/pingcap/docs/blob/master/explain-walkthrough.md Creates tables and inserts data, then uses EXPLAIN to show the default behavior where a scalar subquery is pre-executed and its result is used in the plan. ```sql CREATE TABLE t1(a int); INSERT INTO t1 VALUES(1); CREATE TABLE t2(a int); EXPLAIN SELECT * FROM t2 WHERE a = (SELECT a FROM t1); ``` -------------------------------- ### INSERT basic examples with table creation and data insertion Source: https://github.com/pingcap/docs/blob/master/sql-statements/sql-statement-insert.md Demonstrates creating tables and inserting rows using various INSERT syntaxes: direct VALUES, column-specified VALUES, and SELECT-based insertion. ```sql CREATE TABLE t1 (a INT); ``` ```sql CREATE TABLE t2 LIKE t1; ``` ```sql INSERT INTO t1 VALUES (1); ``` ```sql INSERT INTO t1 (a) VALUES (1); ``` ```sql INSERT INTO t2 SELECT * FROM t1; ``` ```sql INSERT INTO t2 VALUES (2),(3),(4); ``` -------------------------------- ### Uninstall All TiUP Components Source: https://github.com/pingcap/docs/blob/master/tiup/tiup-component-management.md Example of uninstalling all installed TiUP components and their versions. ```shell tiup uninstall --all ``` -------------------------------- ### Clone the pytidb repository Source: https://github.com/pingcap/docs/blob/master/ai/examples/basic-with-pytidb.md Clone the `pytidb` repository to get the example code. ```bash git clone https://github.com/pingcap/pytidb.git cd pytidb/examples/basic/ ``` -------------------------------- ### start-task command help Source: https://github.com/pingcap/docs/blob/master/dm/dm-create-task.md Display help information for the start-task command including all available flags and options. ```bash help start-task ``` -------------------------------- ### Example Docker Command with Specific Path Source: https://github.com/pingcap/docs/blob/master/resources/tidb-pdf-generation-tutorial.md This example shows how to run the Docker image with a specific local documentation path, such as a GitHub repository clone. ```bash docker run -it -v /Users/${username}/Documents/GitHub/docs:/opt/data andelf/doc-build:0.1.9 ``` -------------------------------- ### Start Multiple Component Instances Source: https://github.com/pingcap/docs/blob/master/tiup/tiup-playground.md Deploy multiple instances of TiDB, TiKV, and PD components. This example starts 3 instances of each component for a larger test cluster. ```bash tiup playground --db 3 --pd 3 --kv 3 ``` -------------------------------- ### Create table and insert sample data Source: https://github.com/pingcap/docs/blob/master/as-of-timestamp.md Initial setup to create a test table and populate it with sample rows for demonstration purposes. ```sql create table t (c int); ``` ```sql insert into t values (1), (2), (3); ``` -------------------------------- ### Create Sample Data (macOS MySQL) Source: https://github.com/pingcap/docs/blob/master/dm/quick-start-with-dm.md Creates a 'hello' database, a 'hello_tidb' table, inserts sample data, and selects it for verification. ```sql CREATE DATABASE hello; USE hello; CREATE TABLE hello_tidb ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) ); INSERT INTO hello_tidb (name) VALUES ('Hello World'); SELECT * FROM hello_tidb; ``` -------------------------------- ### TiUP Playground Cluster Start Output Source: https://github.com/pingcap/docs/blob/master/quick-start-with-tidb.md Example output after a TiDB Playground cluster successfully starts, providing connection endpoints for TiDB, TiDB Dashboard, and Grafana. ```log 🎉 TiDB Playground Cluster is started, enjoy! Connect TiDB: mysql --comments --host 127.0.0.1 --port 4000 -u root TiDB Dashboard: http://127.0.0.1:2379/dashboard Grafana: http://127.0.0.1:3000 ``` -------------------------------- ### Successful DM Task Start Output Source: https://github.com/pingcap/docs/blob/master/dm/migrate-data-using-dm.md Example JSON response indicating a successful start of a DM data migration task, showing status for individual workers. ```json { "result": true, "msg": "", "workers": [ { "result": true, "worker": "172.16.10.72:8262", "msg": "" }, { "result": true, "worker": "172.16.10.73:8262", "msg": "" } ] } ``` -------------------------------- ### Using USE to select a database and manage tables Source: https://github.com/pingcap/docs/blob/master/sql-statements/sql-statement-use.md This example demonstrates how to use the `USE` statement to switch between databases, create a new database, and then create a table within the newly selected database. ```sql mysql> USE mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> SHOW TABLES; +-------------------------+ | Tables_in_mysql | +-------------------------+ | GLOBAL_VARIABLES | | bind_info | | columns_priv | | db | | default_roles | | expr_pushdown_blacklist | | gc_delete_range | | gc_delete_range_done | | global_priv | | help_topic | | opt_rule_blacklist | | role_edges | | stats_buckets | | stats_feedback | | stats_histograms | | stats_meta | | stats_top_n | | tables_priv | | tidb | | user | +-------------------------+ 20 rows in set (0.01 sec) mysql> CREATE DATABASE newtest; Query OK, 0 rows affected (0.10 sec) mysql> USE newtest; Database changed mysql> SHOW TABLES; Empty set (0.00 sec) mysql> CREATE TABLE t1 (a int); Query OK, 0 rows affected (0.10 sec) mysql> SHOW TABLES; +-------------------+ | Tables_in_newtest | +-------------------+ | t1 | +-------------------+ 1 row in set (0.00 sec) ``` -------------------------------- ### Start systemd user service Source: https://github.com/pingcap/docs/blob/master/tiup/tiup-cluster-no-sudo-mode.md Start and verify the systemd user service for the tidb user. Run as root user to get the tidb user ID and manage the service. ```shell $ uid=$(id -u tidb) # Get the ID of the tidb user $ systemctl start user@${uid}.service $ systemctl status user@${uid}.service user@1000.service - User Manager for UID 1000 Loaded: loaded (/usr/lib/systemd/system/user@.service; static; vendor preset> Active: active (running) since Mon 2024-01-29 03:30:51 EST; 1min 7s ago Main PID: 3328 (systemd) Status: "Startup finished in 420ms." Tasks: 6 Memory: 6.1M CGroup: /user.slice/user-1000.slice/user@1000.service ├─dbus.service │ └─3442 /usr/bin/dbus-daemon --session --address=systemd: --nofork > ├─init.scope │ ├─3328 /usr/lib/systemd/systemd --user │ └─3335 (sd-pam) └─pulseaudio.service └─3358 /usr/bin/pulseaudio --daemonize=no --log-target=journal ``` -------------------------------- ### Interactive Global Binding Setup Source: https://github.com/pingcap/docs/blob/master/sql-statements/sql-statement-drop-binding.md This snippet shows an interactive session for creating tables and then establishing several global SQL bindings, including the output from each command. ```sql > CREATE TABLE t1(a INT, b INT, c INT, INDEX ia(a)); Query OK, 0 rows affected (0.044 sec) > CREATE TABLE t2(a INT, b INT, c INT, INDEX ia(a)); Query OK, 0 rows affected (0.035 sec) > CREATE GLOBAL BINDING FOR SELECT * FROM t1 WHERE a > 1 USING SELECT * FROM t1 USE INDEX (ia) WHERE a > 1; Query OK, 0 rows affected (0.011 sec) > CREATE GLOBAL BINDING FOR SELECT * FROM t2 WHERE a < 1 USING SELECT * FROM t2 USE INDEX (ia) WHERE a < 1; Query OK, 0 rows affected (0.013 sec) > CREATE GLOBAL BINDING FOR SELECT * FROM t1 JOIN t2 ON t1.b = t2.a USING SELECT /*+ HASH_JOIN(t1) */ * FROM t1 JOIN t2 ON t1.b = t2.a; Query OK, 0 rows affected (0.012 sec) > SHOW GLOBAL BINDINGS; ```