JeecgBoot集成TiDB,打造高效可靠的數據存儲解決方案
TiDB簡(jiǎn)介
TiDB
是PingCAP
公司自主設計、研發(fā)的開(kāi)源分布式關(guān)系型數據庫,同時(shí)支持在線(xiàn)事務(wù)處理與在線(xiàn)分析處理 (Hybrid Transactional and Analytical Processing, HTAP) 的融合型分布式數據庫產(chǎn)品,具備水平擴容或者縮容、金融級高可用、實(shí)時(shí) HTAP、云原生的分布式數據庫、兼容 MySQL 5.7 協(xié)議和 MySQL 生態(tài)等重要特性。
TIDB安裝部署
TiDB
是一個(gè)分布式系統。最基礎的TiDB
測試集群通常由 2 個(gè)TiDB
實(shí)例、3 個(gè)TiKV
實(shí)例、3 個(gè)PD
實(shí)例和可選的TiFlash
實(shí)例構成。
本文只是為了驗證JeecgBoot
與TiDB
的兼容性,所以使用TiUP Playground
在單機搭建了一套測試集群。若用于生產(chǎn)環(huán)境部署,請參閱TiDB
官方文檔。
1、下載并安裝 TiUP。
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
安裝完成后提示:
Successfully set mirror to https://tiup-mirrors.pingcap.com
Detected shell: zsh
Shell profile: /Users/user/.zshrc
/Users/user/.zshrc has been modified to add tiup to PATH
open a new terminal or source /Users/user/.zshrc to use it
Installed path: /Users/user/.tiup/bin/tiup
===============================================
Have a try: tiup playground
===============================================
2、聲明全局環(huán)境變量。
source ${your_shell_profile}
3、在當前 session 執行以下命令啟動(dòng)集群。 執行 tiup playground 命令會(huì )運行最新版本的 TiDB 集群,其中 TiDB、TiKV、PD 和 TiFlash 實(shí)例各 1 個(gè)
tiup playground
運行結果將顯示集群的訪(fǎng)問(wèn)方式:
CLUSTER START SUCCESSFULLY, Enjoy it ^-^
To connect TiDB: mysql --comments --host 127.0.0.1 --port 4000 -u root -p (no password)
To view the dashboard: http://127.0.0.1:2379/dashboard
PD client endpoints: [127.0.0.1:2379 127.0.0.1:2382 127.0.0.1:2384]
To view the Prometheus: http://127.0.0.1:9090
To view the Grafana: http://127.0.0.1:3000
4、使用
Navicat
訪(fǎng)問(wèn)TiDB
JeecgBoot集成TiDB
1、 初始化數據庫
1.1、復制一份
db/jeecgboot-mysql-5.7.sql
文件。1.2、打開(kāi)復制的sql文件,將
sys_tenant
表work_place
字段的字節碼由utf32
為utf8mb4
。
1.3、保存并在數據庫中執行修改后的sql文件。
如果需要將現有的支持Mysql
協(xié)議的數據遷移到TiDB
,可以使用TiDB官方提供的TIDB Data Migration
工具。具體使用方法請參閱TiDB官方文檔。
2、修改JeecgBoot配置文件
修改配置文件中的數據庫連接信息
3、啟動(dòng)項目
打印以下配置代表項目啟動(dòng)成功。