亿级流量点赞系统第六章

项目地址

GitHub地址💥:https://github.com/tenyon61/likeboom

后端初始化模板💥:https://github.com/tenyon61/springboot3-demo/tree/single

快速开始

✨方案选型

选用TiDB数据库替代MySQL

✨部署TiDB

💥腾讯云按量收费

2025-04-28-d748f5.webp

💥执行安装

shell
复制代码
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

安装成功

2025-04-28-f3eec6.webp

立即生效

shell
复制代码
source /root/.bashrc

💥启动数据库

shell
复制代码
tiup playground --tag thumb

启动成功

2025-04-28-47c7e9.webp

💥反代控制台

使用1panel面板,教程链接:https://www.codefather.cn/post/1912901809601032194

2025-04-29-525d79.webp

成功登录

2025-04-29-06b96e.webp

✨数据迁移

💥导出MySQL脚本

2025-04-29-882fa1.webp

💥连接TiDB

2025-04-29-911c82.webp

💥执行脚本

2025-04-29-aea03b.webp

💥功能验证

yaml
复制代码
spring: datasource: url: jdbc:mysql://${datasource.mysql.host}:4000/likeboom username: ${datasource.mysql.username} password: ${datasource.mysql.password} driver-class-name: com.mysql.cj.jdbc.Driver hikari: pool-name: HikariCPDatasource minimum-idle: 5 idle-timeout: 180000 maximum-pool-size: 10 auto-commit: true max-lifetime: 1800000 connection-timeout: 30000 connection-test-query: SELECT 1

如果没用权限需要给root用户授权

shell
复制代码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

执行点赞,成功入库

2025-04-29-9960d2.webp

本章总结

了解和使用TiDB,同时实操将数据库从MySQL丝滑迁移到TiDB,增强水平扩展能力,确保数据强一致性。

项目踩坑

  • 本地windows访问有问题需要修改配置

/root/.tiup/data/thumb/tidb-0/tidb.toml

toml
复制代码
[security] auto-tls = true [server] host = "0.0.0.0" port = 4000

使用命令

shell
复制代码
tiup playground --tag thumb --db.host 0.0.0.0
0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
下载 APP