1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

I tried TiDB on MacBook M2!

Last updated at Posted at 2024-01-31

Table of Contents

  1. Introduction
  2. Environment 
  3. What is TiDB?
  4. What is TiUP Playground?
  5. Download and Install TiUP
  6. Declare the global environment variable
  7. Launch the cluster (TiUP Playground)
  8. Start a new session to access TiDB
  9. Demonstrating TiDB Dashboard
  10. Demonstrating Grafana
  11. Summary
  12. Reference

Introduction

I recently had a chance to hear about TiDB, so I thought I'd give it a try.
I also had an opportunity to attend an event "TiUG KICK OFF" recently held on 26th February 2024 at WESTALL Yotsuya Building.

That was also a good experience to know various features about TiDB.
But this time I am going to share my experience on trying out TiDB on macOS M2.

Environment

  • macOS Ventura v13.0(Apple M2)

What is TiDB?

TiDB, an abbreviation of Titanium Database, is an open source distributed SQL database compatible with MySQL.
It is referred to as NewSQL. Although there are some conditions, it is good to hear that it can be used as MySQL compatible.
This makes me curious to know more about TiDB.
For more information, please refer to the official documentation.

What is TiUP Playground?

TiUP is a tool to download and install TiDB components.
TiUP Playground is the mechanism to build the TiDB clusters.
The basic usage of the playground component is as follows:

tiup playground

Running this command will install TiDB cluster.
Before running this command, you need to download the TiDB cluster.

Download and Install TiUP

First download the TiUP test cluster and then launch the TiDB cluster.
You can download the TiUP from the command below.

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.
If you got the following message, then you have successfully installed TiUP:

Successfully set mirror to https://tiup-mirrors.pingcap.com
Detected shell: zsh
Shell profile:  /Users/testuser/.zshrc
/Users/testuser/.zshrc has been modified to add tiup to PATH
open a new terminal or source /Users/testuser/.zshrc to use it
Installed path: /Users/testuser/.tiup/bin/tiup
===============================================
Have a try:     tiup playground
===============================================

Now, copy the file name from the Shell profile in my case it is .zshrc after that we will declare this variable globally by using the following command.

source .bashrc

Launch the cluster (TiUP Playground)

If you want to start a TiDB cluster of the latest version, run the following command:

tiup playground

After execution of the above code we will get a result in terminal that looks like this.

Screenshot 2024-01-30 at 17.07.40.jpeg

In this result, we can clearly view the information about connecting TiDB, TiDB dashboard, and Grafana.

Start a new session to access TiDB

If you haven't installed the MySQL yet, then use the following command to install:

brew update
brew install mysql

After successful installation, you can use the MySQL client to connect to TiDB.

mysql --host 127.0.0.1 --port 4000 -u root

After this command, we are able to get the MySQL command line in our terminal.

Screenshot 2024-01-30 at 17.26.59.jpeg

Now we can continue working on MySQL like creating database show database and other MySQL queries.

Let's try the show databases option.

These are list of default databases during the MySQL client installed.

Screenshot 2024-01-30 at 17.42.04.jpeg

Let's create a test database called tidb_test using this SQL command.

create database tidb_test;

then change the database to tidb_test using this MySQL command.

use tidb_test;

Next is to create the table name tidb_user;

CREATE TABLE tidb_user(
        User_ID 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),
    Gender  varchar(255),
    Dob  varchar(255),
    PRIMARY KEY (User_ID)
);

and insert data into it.

INSERT INTO tidb_user(FullName, Email, Password) VALUES("Test TiDB User","test_tidb@gmail.com","tidb_123");

after that we can check data of that table;

select * from tidb_user;

Screenshot 2024-01-30 at 17.58.29.png

This will confirm that MySQL is working fine.

Demonstrating TiDB Dashboard

By running tiup playground command, we have got some information related to the TiDB dashboard.
Screenshot 2024-01-30 at 18.14.55.png

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 initially like this:

Screenshot 2024-01-30 at 18.17.24.png

There is a sign in option displayed. The default username is root with password empty. This will log in to the TiDB dashboard.

Screenshot 2024-01-30 at 18.19.53.png

Besides dashboard, there are different other pages, Cluster Info page, Top SQL, SQL Statements, Slow Queries and so on.

Demonstrating Grafana

Grafana is an open source monitoring system for analyzing and visualizing metrics.
Similarly, you can access the grafana by the following link which will display the grafana login page:

http://127.0.0.1:3000

The default username and password for grafana is admin. Use this login details, and later you can set the new password.
This is how the grafana home page looks like.

Screenshot 2024-01-30 at 18.34.47.png

This is all about grafana monitoring.

Summary

I think it's a good experience to use TiDB. It is faster than MySQL as it supports parallel query execution for select queries and can utilize many more CPU cores.
MySQL is limited to a single CPU core for a single select query. But in terms of using a large number of servers, I think it will be challenging to use TiDB unless you have a fairly large-scale environment.
If it's just a small DB, the cost may be prohibitive.
This time I haven't tried the db performance test. But surely I would like to try out various things in the future.

Reference

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?