Quickly deploy of a TiDB database for mac OS (macOS) – local test cluster

This post is about deploying a TiDB database in a non-productive environment. I intend to try the features of Hybrid Transactional and Analytical Processing (HTAP) workloads of this open-source distributed SQL database. It was mind-blowing when I heard about the possibility of a database maintaining the scalability of a NoSQL database while keeping the ACID transactions of a relational database. Therefore, I will follow the procedure “Deploy a local test cluster” found on the official documentation for MacOS as below:

1- Download and install TiUP:

Command:

curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

Execution:

(base) brunotechdatabasket@Brunos-MBP ~ % whoami
brunotechdatabasket
(base) brunotechdatabasket@Brunos-MBP ~ % curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 7658k  100 7658k    0     0  5521k      0  0:00:01  0:00:01 --:--:-- 5525k
…

PATH
open a new terminal or source /Users/brunotechdatabasket/.zshrc to use it
Installed path: /Users/brunotechdatabasket/.tiup/bin/tiup
===============================================
Have a try:     tiup playground
===============================================
(base) brunotechdatabasket@Brunos-MBP ~ % 

2- Declare the global environment variable:

Command:

Note
After the installation, TiUP displays the absolute path of the corresponding Shell profile file. You need to modify ${your_shell_profile} in the following source command according to the path. In this case, ${your_shell_profile} is /Users/user/.zshrc from the output of Step 1.
source ${your_shell_profile}

Execution:

(base) brunotechdatabasket@Brunos-MBP ~ % source /Users/brunotechdatabasket/.zshrc
(base) brunotechdatabasket@Brunos-MBP ~ % 

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

https://docs.pingcap.com/tidb/dev/quick-start-with-tidb#deploy-a-local-test-cluster

Command:

(base) brunotechdatabasket@Brunos-MBP ~ % tiup playground
tiup is checking updates for component playground ...timeout(2s)!
The component `playground` version  is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/playground-v1.12.0-darwin-amd64.tar.gz 8.02 MiB / 8.02 MiB 100.00% 3.15 MiB/s                                                                                
Starting component `playground`: /Users/brunotechdatabasket/.tiup/components/playground/v1.12.0/tiup-playground
Using the version v7.0.0 for version constraint "".
		
If you'd like to use a TiDB version other than v7.0.0, cancel and retry with the following arguments:
	Specify version manually:   tiup playground <version>
	Specify version range:      tiup playground ^5
	The nightly version:        tiup playground nightly

Playground Bootstrapping...
Start pd instance:v7.0.0
The component `pd` version v7.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/pd-v7.0.0-darwin-amd64.tar.gz 48.81 MiB / 48.81 MiB 100.00% 40.68 MiB/s                                                                                      
Start tikv instance:v7.0.0
The component `tikv` version v7.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/tikv-v7.0.0-darwin-amd64.tar.gz 30.99 MiB / 30.99 MiB 100.00% 39.25 MiB/s                                                                                    
Start tidb instance:v7.0.0
The component `tidb` version v7.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/tidb-v7.0.0-darwin-amd64.tar.gz 64.47 MiB / 64.47 MiB 100.00% 42.09 MiB/s                                                                                    
Waiting for tidb instances ready
127.0.0.1:4000 ... Done
The component `prometheus` version v7.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/prometheus-v7.0.0-darwin-amd64.tar.gz 96.82 MiB / 96.82 MiB 100.00% 39.32 MiB/s                                                                              
download https://tiup-mirrors.pingcap.com/grafana-v7.0.0-darwin-amd64.tar.gz 47.24 MiB / 47.24 MiB 100.00% 39.39 MiB/s                                                                                 
Start tiflash instance:v7.0.0
The component `tiflash` version v7.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/tiflash-v7.0.0-darwin-amd64.tar.gz 72.75 MiB / 72.75 MiB 100.00% 9.50 MiB/s                                                                                  
Waiting for tiflash instances ready
127.0.0.1:3930 ... Done
CLUSTER START SUCCESSFULLY, Enjoy it ^-^
To connect TiDB: mysql --comments --host xxxx --port 4000 -u root -p xxxxxxx
To view the dashboard: http://xxxxxx:2379/dashboard
PD client endpoints: [xxxx:2379]
To view the Prometheus: http://xxxxx:9090
To view the Grafana: http://xxxxx:3000

Note to “CLUSTER START SUCCESSFULLY, Enjoy it ^-^”. And to my surprise, after the creation of the cluster is possible to connect to both Prometheus and Grafana dashboards besides the TiDB dashboard.

TiDB dashboard:


To view the dashboard: http://localIP
PDclientendpoints:2379/dashboard

Inside TiDB dashboard:

To view the dashboard: http://localIP
PDclientendpoints:2379/dashboard

Prometheus dashboard:


To view the Prometheus: http://PDclientendpoints:9090

Grafana login page:


To view the Grafana: http://PDclientendpoints:3000

As the cluster was successfully started, I want to connect to it via “mysql –comments –host 127.0.0.1 –port 4000 -u root -p (no password)” as below:

(base) brunotechdatabasket@Brunos-MBP ~ % mysql --comments --host 127.0.0.1 --port 4000 -u root -p  xxxx
zsh: command not found: mysql

As I realized that I did not have the MySQL package, I executed the following command to install it “brew install mysql” which takes approximately 2-3 minutes to release the prompt as the execution below:

==> mysql
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -u root

To restart mysql after an upgrade:
  brew services restart mysql
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql/bin/mysqld_safe --datadir=/usr/local/var/mysql

After installing the MySQL package successfully, it is possible to connect to the TiDB cluster successfully:

(base) brunotechdatabasket@Brunos-MBP v1.12.0 % mysql --comments --host 127.0.0.1 --port 4000 -u root -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 461
Server version: 5.7.25-TiDB-v7.0.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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> 


*Note to “Server version: 5.7.25-TiDB-v7.0.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible”.

Also, it is possible to start a TiUP client to connect to TiDB as below by executing the command “tiup client” the output will start a session and create a view as below:

Related posts

Leave a Comment