TiDB-從0到1-數據導出導入

在這里插入圖片描述

TiDB從0到1系列

  • TiDB-從0到1-體系結構
  • TiDB-從0到1-分布式存儲
  • TiDB-從0到1-分布式事務
  • TiDB-從0到1-MVCC
  • TiDB-從0到1-部署篇
  • TiDB-從0到1-配置篇
  • TiDB-從0到1-集群擴縮容

一、數據導出

TiDB中通過Dumpling來實現數據導出,與MySQL中的mysqldump類似,其屬于邏輯備份,備份出的文件格式為SQL或CSV。
同樣與MySQL中的mysqldump應用場景類似,Dumping最好使用于對小規模的數據備份(導出)

二、Dumpling實操

1、下載安裝

wget https://download.pingcap.org/tidb-community-toolkit-v7.5.1-linux-amd64.tar.gz
------
tar -xvf tidb-community-toolkit-v7.5.1-linux-amd64.tar.gz

2、解壓需要的工具包
在這里插入圖片描述

tar xvf dumpling-v7.5.1-linux-amd64.tar.gz

2、權限控制
使用dumpling的用戶需要有對應的權限

  • select
  • reload
  • lock tables
  • replication client
  • process

3、參數

./dumpling --help
-----------------
Flags:--allow-cleartext-passwords         Allow passwords to be sent in cleartext (warning: don't use without TLS)--azblob.access-tier string         Specify the storage class for azblob--azblob.account-key string         Specify the account key for azblob--azblob.account-name string        Specify the account name for azblob--azblob.encryption-key string      Specify the server side encryption customer provided key--azblob.encryption-scope string    Specify the server side encryption scope--azblob.endpoint string            (experimental) Set the Azblob endpoint URL--azblob.sas-token string           Specify the SAS (shared access signatures) for azblob--ca string                         The path name to the certificate authority file for TLS connection--case-sensitive                    whether the filter should be case-sensitive--cert string                       The path name to the client certificate file for TLS connection--complete-insert                   Use complete INSERT statements that include column names-c, --compress string                   Compress output file type, support 'gzip', 'snappy', 'zstd', 'no-compression' now--consistency string                Consistency level during dumping: {auto|none|flush|lock|snapshot} (default "auto")--csv-delimiter string              The delimiter for values in csv files, default '"' (default "\"")--csv-line-terminator string        The line terminator for csv files, default '\r\n' (default "\r\n")--csv-null-value string             The null value used when export to csv (default "\\N")--csv-separator string              The separator for csv files, default ',' (default ",")-B, --database strings                  Databases to dump--dump-empty-database               whether to dump empty database (default true)--escape-backslash                  use backslash to escape special characters (default true)-F, --filesize string                   The approximate size of output file--filetype string                   The type of export file (sql/csv)-f, --filter strings                    filter to select which tables to dump (default [*.*,!/^(mysql|sys|INFORMATION_SCHEMA|PERFORMANCE_SCHEMA|METRICS_SCHEMA|INSPECTION_SCHEMA)$/.*])--gcs.credentials-file string       (experimental) Set the GCS credentials file path--gcs.endpoint string               (experimental) Set the GCS endpoint URL--gcs.predefined-acl string         (experimental) Specify the GCS predefined acl for objects--gcs.storage-class string          (experimental) Specify the GCS storage class for objects--help                              Print help message and quit-h, --host string                       The host to connect to (default "127.0.0.1")--key string                        The path name to the client private key file for TLS connection-L, --logfile path                      Log file path, leave empty to write to console--logfmt format                     Log format: {text|json} (default "text")--loglevel string                   Log level: {debug|info|warn|error|dpanic|panic|fatal} (default "info")-d, --no-data                           Do not dump table data--no-header                         whether not to dump CSV table header-m, --no-schemas                        Do not dump table schemas with the data--no-sequences                      Do not dump sequences (default true)-W, --no-views                          Do not dump views (default true)--order-by-primary-key              Sort dump results by primary key through order by sql (default true)-o, --output string                     Output directory (default "./export-2024-06-26T11:19:24+08:00")--output-filename-template string   The output filename template (without file extension)--params stringToString             Extra session variables used while dumping, accepted format: --params "character_set_client=latin1,character_set_connection=latin1" (default [])-p, --password string                   User password-P, --port int                          TCP/IP port to connect to (default 4000)-r, --rows uint                         If specified, dumpling will split table into chunks and concurrently dump them to different files to improve efficiency. For TiDB v3.0+, specify this will make dumpling split table with each file one TiDB region(no matter how many rows is).If not specified, dumpling will dump table without inner-concurrency which could be relatively slow. default unlimited--s3.acl string                     (experimental) Set the S3 canned ACLs, e.g. authenticated-read--s3.endpoint string                (experimental) Set the S3 endpoint URL, please specify the http or https scheme explicitly--s3.external-id string             (experimental) Set the external ID when assuming the role to access AWS S3--s3.provider string                (experimental) Set the S3 provider, e.g. aws, alibaba, ceph--s3.region string                  (experimental) Set the S3 region, e.g. us-east-1--s3.role-arn string                (experimental) Set the ARN of the IAM role to assume when accessing AWS S3--s3.sse string                     Set S3 server-side encryption, e.g. aws:kms--s3.sse-kms-key-id string          KMS CMK key id to use with S3 server-side encryption.Leave empty to use S3 owned key.--s3.storage-class string           (experimental) Set the S3 storage class, e.g. STANDARD--snapshot string                   Snapshot position (uint64 or MySQL style string timestamp). Valid only when consistency=snapshot-s, --statement-size uint               Attempted size of INSERT statement in bytes (default 1000000)--status-addr string                dumpling API server and pprof addr (default ":8281")-T, --tables-list strings               Comma delimited table list to dump; must be qualified table names-t, --threads int                       Number of goroutines to use, default 4 (default 4)--tidb-mem-quota-query uint         The maximum memory limit for a single SQL statement, in bytes.-u, --user string                       Username with privileges to run the dump (default "root")-V, --version                           Print Dumpling version--where string                      Dump only selected records

4、導出數據
導出test庫下的所有數據,同時指定導出文件為sql,導出目錄為/tmp/test,導出線程2,每10w行數據切換一次文件,每200MB切換一次文件

./dumpling -h192.168.14.121 -P4000 -uroot -p123456 --filetype sql -t 2 -o /tmp/test -r 100000 -F200MiB -B test

在這里插入圖片描述
(備份成功)

查看導出的內容
在這里插入圖片描述
其中

  • metadata:數據導出時的時間,binlog位置點
  • xxx.schema.sql:建庫建表語句
  • xxx.000000100.sql:數據

導出test庫下t1的表中id>10的數據,同時指定導出文件為CSV,導出目錄為/tmp/t1,導出線程2,每100行數據切換一次文件,每100MB切換一次文件

./dumpling -h192.168.14.121 -P4000 -uroot -p123456 --filetype csv -t 2 -o /tmp/t1 -r 100 -F100MiB -T test.t1 --where "id>10"

在這里插入圖片描述
(備份成功)

查看導出的內容
在這里插入圖片描述
建庫\建表語句依舊是SQL文件
不過數據為CSV格式

同時Dumpling默認也是一致性備份,通過MVCC機制備份出某個時間點的快照數據

三、數據導入

TiDB中提供了一種叫TiDB Lightning(Physical Import Mode模式)的數據導入方式,因為其導入過程TiDB是不能對外提供服務的,而且數據是從本地直接導入到TiKV,所以應用場景更適合TiDB集群初始化。
整個Lightning原理如下

  • 將集群切換為導入模式
  • 創建對應庫表
  • 分割導入數據源
  • 讀取數據源文件
  • 將源數據文件寫入本地臨時文件
  • 導入臨時文件到TiKV集群
  • 檢驗與分析
  • 將集群切換回正常模式

四、Lightning實操

1、下載安裝

wget https://download.pingcap.org/tidb-community-toolkit-v7.5.1-linux-amd64.tar.gz
------
tar -xvf tidb-community-toolkit-v7.5.1-linux-amd64.tar.gz

2、解壓需要的工具包
在這里插入圖片描述

tar xvf tidb-lightning-v7.5.1-linux-amd64.tar.gz

3、準備配置文件

vim tidb-lighning.toml
-----------------
[lightning]
#邏輯cpu數量
#region-concurrency = 
#日志
level = "info"
file = "tidb-lighning.log"[tikv-importer]
#開啟并行導入
incremental-import = true
#設置為local模式
backend = "local"
#設置本地臨時存儲路徑
sorted-kv-dir = "/tmp/sorted-kv-dir"[mydumper]
#源數據目錄
data-source-dir = "/tmp/test"[tidb]
#tidb-server監聽地址
host = "192.168.14.121"
port = 4000
user = "root"
password = ""
#表架構信息
status-port = 10080
#pd地址
pd-addr = "192.168.14.122:2379"

4、導入數據
我這里就將原集群清空,然后將上面-B導出的test庫恢復回去

./tidb-lightning --config /opt/tidb-lighning.toml

在這里插入圖片描述
(導入成功)

5、進入數據庫校驗
在這里插入圖片描述
(驗證無誤)

彩蛋

TiDB-Lightning功能強大,可以通過配置文件過濾導入指定的表,同時也支持將MySQL中分庫分表數據導入到TiDB中合并為一張表,還有斷點續傳等功能。
具體可以參考官方文檔

在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/37303.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/37303.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/37303.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Spring Boot中如何配置和使用多數據源

Spring Boot中如何配置和使用多數據源 大家好,我是免費搭建查券返利機器人省錢賺傭金就用微賺淘客系統3.0的小編,也是冬天不穿秋褲,天冷也要風度的程序猿!今天,我們將深入探討如何在Spring Boot應用中配置和使用多數據…

oracle with as 是什么并且怎么用

Oracle中的WITH AS語句,也被稱為Common Table Expressions(CTE),是一個用于定義臨時結果集或視圖的子句。這個臨時結果集或視圖只在當前的查詢中存在,并且在查詢完成后會被自動刪除。使用WITH AS可以提高SQL語句的可讀…

JavaWeb——MySQL:navicate客戶端工具簡單使用

目錄 1. 連接 2. 新建數據庫 3. 使用數據庫 4. 新建表 5.使用表 6. 導出數據庫 我這里是英文版,沒有進行漢化。 1. 連接 點擊左上角Connection,選擇MySQL,(我連接的是自己計算機上的數據庫)連接名輸入&#x…

使用ScheduledExecutorService進行任務調度

使用ScheduledExecutorService進行任務調度 大家好,我是免費搭建查券返利機器人省錢賺傭金就用微賺淘客系統3.0的小編,也是冬天不穿秋褲,天冷也要風度的程序猿! 在軟件開發中,任務調度是一項重要的技術需求&#xff…

抖音開放平臺運營同學聯系我了,非常感謝

大家好,我是小悟 是怎么個事呢? 前幾天在對接抖音開放平臺,服務商代開發小程序里面的小程序備案,上傳備案圖片接口遇到了問題,具體的問題可詳閱【抖音開放平臺,這誰寫的,要扣績效吧】。 評論…

Zoom視頻會議的虛擬背景功能:打造個性化會議體驗

在遠程工作和在線交流日益普及的今天,視頻會議已成為連接人們的橋梁。Zoom視頻會議軟件因其出色的音視頻質量和豐富的功能而廣受歡迎。其中,虛擬背景功能是Zoom的一大亮點,它不僅能夠保護用戶隱私,還能為會議增添趣味性。本文將詳…

Java編程基本功大揭秘 | 詳解深入分析Java線程池源碼和底層原理,掌握實戰技巧【1】

詳解深入分析Java線程池源碼和底層原理 文章大綱引言Java線程池概念及重要性 ThreadPoolExecutor類的概述ThreadPoolExecutor類的基本功能和作用**基本功能****核心作用** ThreadPoolExecutor主要構造函數及其參數繼承關系鏈功能介紹ThreadPoolExecutor 構造器構造器參數構造器…

c語言自動售貨機

C語言編寫的自動售貨機程序可以模擬真實自動售貨機的基本功能&#xff0c;例如選擇商品、顯示價格、付款和找零。下面是一個簡單的示例代碼&#xff0c;展示了一個基本的自動售貨機程序&#xff1a; #include <stdio.h>// 商品結構體 typedef struct {char name[30];int…

破解對LabVIEW的偏見

LabVIEW被廣泛應用于科學研究、工程測試和自動化控制領域&#xff0c;具有專業性和高效的開發能力。盡管有人對其存在偏見&#xff0c;認為不如C語言&#xff0c;但LabVIEW的圖形化編程、強大集成能力、豐富社區支持和專業功能&#xff0c;使其在許多實際應用中表現出色。通過多…

Go語言環境安裝

Go下載地址 哪個能用用哪個。 https://go.dev/ https://golang.google.cn/&#xff08;Golang官網的官方鏡像&#xff09; Windows 使用.msi安裝包安裝 下載msi文件 安裝 雙擊運行go1.22.4.windows-amd64.msi Next 勾選I accept the terms in the License Agreement&…

收藏 | SSL證書無效的原因和解決辦法

當瀏覽器訪問一個使用SSL證書保護的網站時&#xff0c;會檢查其證書的有效性。如果發現證書存在問題&#xff0c;瀏覽器會顯示“SSL證書無效”的警告信息&#xff0c;提醒用戶存在潛在的安全風險。 “SSL證書無效”的警告可能會導致用戶離開站點&#xff08;并且永遠不會返回&…

MySQL高級-SQL優化-小結

文章目錄 1、insert 優化2、主鍵優化3、order by 優化4、group by 優化5、limit 優化6、count 優化7、update 優化 1、insert 優化 insert&#xff1a;批量插入、手動控制事務、主鍵順序插入 大批量插入&#xff1a;load data local infile 2、主鍵優化 主鍵長度盡量短、順序插…

系統漏洞復現與勒索病毒

知識點&#xff1a;SMB漏洞介紹、漏洞復現流程、勒索病毒攻擊與防護 滲透測試相關&#xff1a; 基本概念&#xff1a; 滲透測試就是利用我們所掌握的滲透知識&#xff0c;對網站進行一步一步的滲透&#xff0c;發現其中存在的漏洞和隱藏的風險&#xff0c;然后撰寫一篇測試報…

FastAPI教程I

本文參考FastAPI教程https://fastapi.tiangolo.com/zh/tutorial 第一步 import uvicorn from fastapi import FastAPIapp FastAPI()app.get("/") async def root():return {"message": "Hello World"}if __name__ __main__:uvicorn.run(&quo…

GPT-4o模型到底有多強

近年來&#xff0c;人工智能技術突飛猛進&#xff0c;在自然語言處理&#xff08;NLP&#xff09;和計算機視覺等領域取得了令人矚目的成就。OpenAI推出的GPT-4o模型作為最新一代的語言模型&#xff0c;進一步提升了AI的能力&#xff0c;尤其在文檔分析、識圖生文、文生圖等功能…

elementUI的搭建使用過程

Element - The worlds most popular Vue UI framework 上面是elementUI的網站,進入網站 點擊右上角的組件按鈕 復制這段代碼到你的項目終端:npm i element-ui -S 加載完成后即可使用elementUI網站中的組件,使用它們只需要復制組件下面的代碼即可

Unity UGUI 實現簡單兩點連線功能

實現 記錄鼠標點擊位置為線段起點。 posStart Input.mousePosition; 創建一個Image 作為線段。 line new GameObject("line"); rtLine line.AddComponent<RectTransform>(); rtLine.pivot new Vector2(0, 0.5f); rtLine.localScale Vector3.one; img…

Linux 進程通信

1.什么是進程通信&#xff1f; 答&#xff1a;兩個或多個進程實現數據層面的交互&#xff1b;但是因為進程的獨立性&#xff0c;導致進程通信的成本較高&#xff1b; 2.為什么要通信&#xff1f; 答&#xff1a;多進程之間由協同的需求&#xff0c;所以通信&#xff1b;以下…

Java常用對象的快速初始化

在Java中&#xff0c;有多種方式來快速初始化各種常用對象&#xff0c;如字符串數組&#xff08;String[]&#xff09;&#xff0c;集合列表&#xff08;List&#xff09;&#xff0c;映射表&#xff08;Map&#xff09;&#xff0c;以及集合&#xff08;Set&#xff09;。不同…

動態服務管理的藝術:Eureka在服務擴展與收縮中的策略

動態服務管理的藝術&#xff1a;Eureka在服務擴展與收縮中的策略 在微服務架構中&#xff0c;服務的動態擴展和收縮是實現高可用性和彈性的關鍵。Eureka&#xff0c;作為Netflix開源的服務發現框架&#xff0c;提供了一套機制來處理服務實例的動態變化。本文將深入探討Eureka如…