Introduction to PingCap/TiDB/  Part-1 Installation of TiDB on Windows machine. 
Tags: pingcap
Published: 2021-04-02 19:33:39

**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**

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqnyh9qq3ke3fe63mv73.png)

then click on the **Programs** option at the bottom.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e8qsvj62o82prjkjkkj4.png)

under the **Programs and Features** category click on the **Turn Windows feature on and off** option.


![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ijz5eg42mr8g8bq5waq.png)
 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](https://docs.microsoft.com/en-us/windows/wsl/install-win10) 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](https://www.microsoft.com/en-us/p/ubuntu-2004-lts/9n6svws3rx71?activetab=pivot:overviewtab). when you click the link you will get this page. 
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cypvnzauton5mpgni733.png)
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.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tdf9tbij9lm6mbkuch4a.png)
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.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1n6b01pimbehi2hi0ett.png)


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.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6rcy0jylyzsx3iokjvbg.png)
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:**
```cmd
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.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avnk94c50h8od5nz8kzi.png)
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.

```cmd 
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.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hr622n42vdnwstvakeos.png)

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.**

```cmd
 yum -y install MySQL
```

      

**Use the MySQL client to connect to TiDB.**

```cmd
   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.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/seyi5bbmkwse97cuhp7o.png)


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.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h2jx02zyziiuyi52biac.png)

now I am going to create a database called **FixItDb** using this SQL command. 

```sql
   create database FixItDb;
```

then I will change the database to **FixItDb** using this MySQL command. 

```sql
   use FixItDb;
```

let us create one table called User. 

```SQL
  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.

```SQL
INSERT INTO user(FullName,Email,Password,RoleId) VALUES("Yared Solomon","yaredyaya16@gmail.com","yared",1);
```
after that let us check our database;

```SQL
  select * from user;
```

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tf6q2wdogwf3lcq51k4y.png)

*so MySQL is working fine*

#**Demonstrating TiDB Dashboard**
we have got these three pieces of information when TiDB playground run.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y80278fj5r56mbcct016.png)

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.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0larl101cw6iwck1fa4k.png)

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. 

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eg9uy2jo2x7vnlqgvvjl.png)
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. 

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4gti4yurcjyy4sm3fwwf.png)

next to this, we get the **SQL statement** which contains some SQL statements that have been performed on the TiDB server.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2878wl35gic0o9kkp2yl.png)

*The SQL statements we did before on the MySQL will appear here* let us filter it by database and have a look at it.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w5sehq42bmezzq1quazy.png)
next to this, we have the **Slow Queries**  that contains queries that need some time to load. 

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vkxgz28hjv4cxrmmyz8p.png)
 
after this, there is an option called **Key visualizer** that has a visualization option for the execution performed on the TiDB server.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ogxdbgxt0y5bo22xwtz8.png)

this is what the **Cluster Diagnostic** page looks like.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/354ctjhuqcckvfy7ol88.png)
#**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.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v603tnj6px5vh7a4yb0o.png)
#**Demonstrating Grafana** 
Similarly, there is also a link for grafana. which will display the grafana login page. 

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5opq865i484sfejsaa0z.png)
 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.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y2s25m3wb7wuhpaez5ks.png)
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. 

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rb7kwfjwrposxedfw2c5.png)

 

That is all about this part we will see **Grafana monitoring**  in the next part of this article. 

Thank you!