What is TiDb?
TiDB (/’taɪdiːbi:/, "Ti" stands for Titanium) is an open-source NewSQL database that supports Hybrid Transactional and Analytical Processing (HTAP) workloads. It is MySQL compatible and features horizontal scalability, strong consistency, and high availability. The goal of TiDB is to provide users with a one-stop database solution that covers OLTP (Online Transactional Processing), OLAP (Online Analytical Processing), and HTAP services. TiDB is suitable for various use cases that require high availability and strong consistency with large-scale data.
Getting started with TiDB
How to install TiDB on Windows machine?
TiDB runs on top of the Linux operating system so it is not possible to directly install it to a windows machine. We have different ways to install TiDB on Windows. like using local Linux virtual machine, cloud Linux virtual machine(Azure, AWS), and using Window's subsystem for Linux.In this article, we are going to focus on the installation of TiDB using Windows subsystem for Linux.
Step 0:Check if WSL already existed in our computer
before going to step 1 make sure that your computer has or has no windows subsystem for Linux because some programs like docker will install it by themselves.
so go to Control Panel
then click on the Programs option at the bottom.
under the Programs and Features category click on the Turn Windows feature on and off option.
from this page find the windows subsystem for the Linux windows feature. in my case, because I have already installed you can see that there is an option for that around the bottom. if you get it already installed make sure that it is turned on. unless otherwise follow this Tutorial to install it and make sure to turn it on after installation finished.
Step 1:Install Ubuntu on top of Wsl
Wsl helps us to install ubuntu on our windows machine without a virtual machine. it will be like other software running on the computer. now let us install Ubuntu 20.04.LTS. when you click the link you will get this page.
Click on the Get option. we are going to download it from Microsoft store. so when you click that the browser will prompt you with a dialog box.
Click on Open Microsoft store. you will get the Microsoft store page. download it with the Get button provided.
when the download finished, click the launch button at the top.
because you are running it for the first time you need to provide a user name and password information. after that, you will get an ubuntu terminal that consists of the username you gave before.
so we have successfully installed ubuntu on our windows machine.
Step 2:Install TiDB on Ubuntu
All the next TiDB configuration will be done on the ubuntu terminal we installed.
As a distributed system, a basic TiDB test cluster usually consists of 2 TiDB instances, 3 TiKV instances, 3 PD instances, and optional TiFlash instances. With TiUP Playground, you can quickly build the above test cluster by taking the following steps:
Download and install TiUP:
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
Declare the global environment variable:
After the installation, TiUP displays the absolute path of the corresponding profile file. You need to modify the following source command according to the path.
copy only the file name from the Shell profile in my case it is .bashrc after that we will declare this variable globally by using the following command.
source .bashrc
Start the cluster in the current session:
If you want to start a TiDB cluster of the latest version with 1 TiDB instance, 1 TiKV instance, 1 PD instance, and 1 TiFlash instance, run the following command:
tiup playground
If you want to specify the TiDB version and the number of the instances of each component, run a command like this:
tiup playground v4.0.0 --db 2 --pd 3 --kv 3 --monitor
The command downloads a v4.0.0 cluster to the local machine and starts it. --monitor means that the monitoring component is also deployed.
after we executed the code we will get a page that looks like this.
It has information about Prometheus, TiDB Dashboard and Grafana we will see later what these pages look like.
Start a new session to access TiDB:
Install the MySQL client. If it is already installed, skip this step.
yum -y install MySQL
Use the MySQL client to connect to TiDB.
mysql --host 127.0.0.1 --port 4000 -u root
after this command, we can able to get the MySQL command line on our terminal.
now we can continue working on MySQL like creating database show database and other MySQL queries.
let us try the show databases option.
These databases existed by default when the MySQL client installed.
now I am going to create a database called FixItDb using this SQL command.
create database FixItDb;
then I will change the database to FixItDb using this MySQL command.
use FixItDb;
let us create one table called User.
CREATE TABLE User(
UserId int NOT NULL AUTO_INCREMENT,
FullName varchar(255) NOT NULL,
Email varchar(255) NOT NULL,
Password varchar(255) NOT NULL,
Phone varchar(255),
Address varchar(255),
Picture varchar(255),
Sex varchar(255),
Dob varchar(255),
RoleId int NOT NULL,
PRIMARY KEY (UserId)
);
and insert some data into it.
INSERT INTO user(FullName,Email,Password,RoleId) VALUES("Yared Solomon","yaredyaya16@gmail.com","yared",1);
after that let us check our database;
select * from user;
so MySQL is working fine
Demonstrating TiDB Dashboard
we have got these three pieces of information when TiDB playground run.
from these let us have a look at the TiDB dashboard.
The host's IP address will be the IP address of the local machine. because we are not running on the virtual machine there will not be any different IP address from the host machine.
The dashboard looks like this initially.
as you can see there is a sign-in option. The default username is the root, with an empty password. when we sign in using this information we will get the overview page.
This page is the overview of different information that existed on the dashboard.
We have the Cluster info option at the bottom of the overview this gives information about the host machine and the running instances.
next to this, we get the SQL statement which contains some SQL statements that have been performed on the TiDB server.
The SQL statements we did before on the MySQL will appear here let us filter it by database and have a look at it.
next to this, we have the Slow Queries that contains queries that need some time to load.
after this, there is an option called Key visualizer that has a visualization option for the execution performed on the TiDB server.
this is what the Cluster Diagnostic page looks like.
TiDB Monitoring Framework Overview
The TiDB monitoring framework adopts two open-source projects: Prometheus and Grafana. TiDB uses Prometheus to store the monitoring and performance metrics and Grafana to visualize these metrics.
Demonstrating Prometheus
From the information, we got when TiDB playground runs. there is a link for Prometheus. if we click it we will get the Prometheus home page.
Demonstrating Grafana
Similarly, there is also a link for grafana. which will display the grafana login page.
The default user name and password are admin for both.
after we logged in using the default username and password we get a page that looks like this.
it allows us to change the default password for the user admin.
so enter a new password and click on the save button. then we will get the home page.
That is all about this part we will see Grafana monitoring in the next part of this article.
Thank you!
Top comments (0)