TiDB

简介

TiDB 是一款定位于在线事务处理/在线分析处理( HTAP: Hybrid Transactional/Analytical Processing)的融合型数据库产品,实现了一键水平伸缩、强一致性的多副本数据安全、分布式事务、实时 OLAP 等重要特性,同时兼容 MySQL 协议和生态,迁移便捷,运维成本极低。

[ 文档 | 代码 | 社区]

部署

1. 安装依赖包

1
$ yum -y install libtool zlib-devel autoconf readline-devel readline libuuid-devel zlib-devel automake libuuid readline-devel readline ncurses-devel.x86_64 ncurses.x86_64 gcc-c++ vim wget net-tools svn libstdc++.so.6 glibc.i686 unzip make lrzsz libtool zlib-devel autoconf readline-devel readline libuuid-devel zlib-devel automake libuuid readline-devel readline ncurses-devel.x86_64 ncurses.x86_64 gcc-c++ vim wget net-tools svn libstdc++.so.6 libcurl-dev libcurl-devel expat-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker zip git gcc openssl-devel libnl3-devel net-snmp-devel libnfnetlink-devel zlib zlib-devel openssl openssl-devel tree lrzsz tree net-tools nmap vim bash-completion lsof dos2unix nc telnet ntp wget rng-tools psmisc screen pcre pcre-devel

2. 安装 TiDB

1
2
3
4
5
6
7
8
9
10
$ cd /usr/local/
$ wget http://download.pingcap.org/tidb-latest-linux-amd64.tar.gz
$ tar -xzf tidb-latest-linux-amd64.tar.gz /usr/local
$ mkdir -p /data/tidb
$ cd /usr/local/tidb-latest-linux-amd64
$ ln -s /usr/local/tidb-latest-linux-amd64/bin/pd-tso-bench /usr/bin
$ ln -s /usr/local/tidb-latest-linux-amd64/bin/tikv-server /usr/bin/
$ ln -s /usr/local/tidb-latest-linux-amd64/bin/tidb-server /usr/bin/
$ ln -s /usr/local/tidb-latest-linux-amd64/bin/pd-server /usr/bin/
$ ln -s /usr/local/tidb-latest-linux-amd64/bin/pd-ctl /usr/bin/

3. 启动 PD

1
2
$ cd bin
$ ./pd-server -data-dir=/data/tidb/pd -log-file=/data/tidb/log/pd.log -name=pd1 &

4. 启动 TiKV

1
$ ./tikv-server --pd="127.0.0.1:2379" --data-dir=/data/tidb/tikv --log-file=/data/tidb/log/tikv.log &

5. 连接 TiDB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ mysql -h 127.0.0.1 -P 4000 -u root

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.25-TiDB-v3.0.0-rc.1-290-g21d2590ac MySQL Community Server (Apache License 2.0)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| INFORMATION_SCHEMA |
| PERFORMANCE_SCHEMA |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)

6. 修改密码

1
2
3
mysql> use mysql; 
mysql> update user set password=PASSWORD("Changeme_123") where User='root';
mysql> flush privileges;

7. 设置远程可访问

1
2
mysql> grant all privileges on *.* to 'root'@'%' identified by 'Changeme_123';
mysql> flush privileges;