Local Install via source for Mac

Instructions for using Vitess on your macOS machine for testing purposes

This guide covers installing Vitess locally for testing purposes, from pre-compiled binaries. We will launch multiple copies of mysqld, so it is recommended to have greater than 4GB RAM, as well as 20GB of available disk space.

A pure homebrew setup is also available.

Install Brew

For the purposes of installing software you will need to have brew installed. This will also install curl and git which will also be needed:

  1. curl https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh > brew-install.sh
  2. bash brew-install.sh

Install MySQL and etcd

Once brew is installed you will need to install some dependencies for Vitess. Vitess supports the databases listed here:

  1. brew install automake go mysql mysql-client etcd

When MySQL installs with brew it will startup, you will want to shut this process down, as Vitess will be managing the startup and shutdown of MySQL:

  1. $ brew services stop mysql

Install Node 18.16.0+ (required to run VTAdmin)

  1. brew install nvm
  2. nvm install --lts 18.16.0
  3. nvm use 18.16.0

See the vtadmin README for more details.

PATH Settings

With the tools you’ve just installed via brew, you will next update your PATH variable so your shell knows where to find the binaries:

  1. echo export PATH=${PATH}:/opt/homebrew/opt/mysql-client/bin:/opt/homebrew/opt/mysql/bin:~/Github/vitess/bin:/Users/jason/go/bin:​​/opt/homebrew/bin >> ~/.zshrc
  2. source ~/.zshrc

If you’re using bash for your shell you’ll have to update the paths in .bash_profile or .bashrc instead. Mac does not read .bashrc by default:

  1. $ echo export PATH=${PATH}:/opt/homebrew/opt/mysql-client/bin:/opt/homebrew/opt/mysql/bin:~/Github/vitess/bin:/Users/jason/go/bin:/opt/homebrew/bin >> ~/.bash_profile
  2. $ source ~/.bash_profile

System Check

Before going further, you should check to confirm your shell has access to go, mysql, and mysqld. If versions are not returned when you run the following commands you should check that the programs are installed and the path is correct for your shell:

  1. $ mysqld --version
  2. $ mysql --version
  3. $ go version
  4. $ etcd --version
  5. $ node --version
  6. $ npm --version

Install Vitess

With everything now in place you can clone and build Vitess.

  1. $ git clone https://github.com/vitessio/vitess.git
  2. $ cd vitess
  3. $ make build

It will take some time for Vitess to build. Once it completes you should see a bin folder which will hold the Vitess binaries. You will need to add this folder to your PATH variable as well:

  1. $ cd bin
  2. $ echo "$(printf 'export PATH="${PATH}:'; echo "$(pwd)\"")" >> ~/.zshrc
  3. $ source ~/.zshrc

If you are using bash this will need to be your .bash_profile or .bashrc file instead:

  1. $ cd bin
  2. $ echo "$(printf 'export PATH="${PATH}:'; echo "$(pwd)\"")" >> ~/.bash_profile
  3. $ source ~/.bash_profile

You are now ready to start your first cluster! Open a new terminal window to ensure your .bashrc file changes take effect.

Start a Single Keyspace Cluster

You are now ready to stand up your first Vitess cluster, using the example scripts provided in the source code. Assuming you are still in the bin directory you will need to navigate to the sample files:

  1. $ cd ../examples/local/

From here you can startup the cluster and source the env file which will help set environment variables used when working with this local cluster:

  1. $ ./101_initial_cluster.sh
  2. $ source ../common/env.sh

You should see an output similar to the following:

  1. $ ./101_initial_cluster.sh
  2. $ ./101_initial_cluster.sh
  3. add /vitess/global
  4. add /vitess/zone1
  5. add zone1 CellInfo
  6. Created cell: zone1
  7. etcd start done...
  8. Starting vtctld...
  9. vtctld is running!
  10. Successfully created keyspace commerce. Result:
  11. {
  12. "name": "commerce",
  13. "keyspace": {
  14. "served_froms": [],
  15. "keyspace_type": 0,
  16. "base_keyspace": "",
  17. "snapshot_time": null,
  18. "durability_policy": "semi_sync",
  19. "throttler_config": null,
  20. "sidecar_db_name": "_vt"
  21. }
  22. }
  23. Starting MySQL for tablet zone1-0000000100...
  24. Starting vttablet for zone1-0000000100...
  25. HTTP/1.1 200 OK
  26. Date: Mon, 26 Jun 2023 19:21:51 GMT
  27. Content-Type: text/html; charset=utf-8
  28. Starting MySQL for tablet zone1-0000000101...
  29. Starting vttablet for zone1-0000000101...
  30. HTTP/1.1 200 OK
  31. Date: Mon, 26 Jun 2023 19:21:54 GMT
  32. Content-Type: text/html; charset=utf-8
  33. Starting MySQL for tablet zone1-0000000102...
  34. Starting vttablet for zone1-0000000102...
  35. HTTP/1.1 200 OK
  36. Date: Mon, 26 Jun 2023 19:21:56 GMT
  37. Content-Type: text/html; charset=utf-8
  38. vtorc is running!
  39. - UI: http://localhost:16000
  40. - Logs: /Users/florentpoinsard/Code/vitess/vtdataroot/tmp/vtorc.out
  41. - PID: 49556
  42. New VSchema object:
  43. {
  44. "sharded": false,
  45. "vindexes": {},
  46. "tables": {
  47. "corder": {
  48. "type": "",
  49. "column_vindexes": [],
  50. "auto_increment": null,
  51. "columns": [],
  52. "pinned": "",
  53. "column_list_authoritative": false,
  54. "source": ""
  55. },
  56. "customer": {
  57. "type": "",
  58. "column_vindexes": [],
  59. "auto_increment": null,
  60. "columns": [],
  61. "pinned": "",
  62. "column_list_authoritative": false,
  63. "source": ""
  64. },
  65. "product": {
  66. "type": "",
  67. "column_vindexes": [],
  68. "auto_increment": null,
  69. "columns": [],
  70. "pinned": "",
  71. "column_list_authoritative": false,
  72. "source": ""
  73. }
  74. },
  75. "require_explicit_routing": false
  76. }
  77. If this is not what you expected, check the input data (as JSON parsing will skip unexpected fields).
  78. Waiting for vtgate to be up...
  79. vtgate is up!
  80. Access vtgate at http://Florents-MacBook-Pro-2.local:15001/debug/status
  81. vtadmin-api is running!
  82. - API: http://Florents-MacBook-Pro-2.local:14200
  83. - Logs: /Users/florentpoinsard/Code/vitess/vtdataroot/tmp/vtadmin-api.out
  84. - PID: 49695
  85. vtadmin-web is running!
  86. - Browser: http://Florents-MacBook-Pro-2.local:14201
  87. - Logs: /Users/florentpoinsard/Code/vitess/vtdataroot/tmp/vtadmin-web.out
  88. - PID: 49698

If you encounter any errors, such as ports already in use, you can kill the processes and start over. Ensure you’re in the vitess/examples/local directory, then issue the statement to kill the processes and remove the data directory. This data directory vtdataroot will get recreated when you run the 101_initial_cluster.sh startup script again.

  1. user@computer:~/Github/vitess/examples/local$ pwd
  2. /home/user/Github/vitess/examples/local
  3. user@computer:~/Github/vitess/examples/local$ pkill -9 -f '(vtdataroot|VTDATAROOT|vitess|vtadmin)'
  4. etcd killed (pid 224091)
  5. vtctld killed (pid 224154)
  6. mysqld_safe killed (pid 224247)
  7. mysqld killed (pid 224716)
  8. vttablet killed (pid 224764)
  9. mysqld_safe killed (pid 224897)
  10. mysqld killed (pid 225364)
  11. vttablet killed (pid 225413)
  12. mysqld_safe killed (pid 225529)
  13. mysqld killed (pid 225995)
  14. vttablet killed (pid 226045)
  15. vtgate killed (pid 226204)
  16. vtadmin killed (pid 226391)
  17. vtorc killed (pid 226397)
  18. user@computer:~/Github/vitess/examples/local$ rm -rf ./vtdataroot

Connect to your cluster

You should now be able to connect to the VTGate server that was started in 101_initial_cluster.sh:

  1. $ mysql -P 15306 -u root --protocol tcp

You can also now browse and administer your new Vitess cluster using the VTAdmin UI at the following URL:

  1. http://localhost:14201

VTOrc is also setup as part of the initialization. You can look at its user-interface at:

  1. http://localhost:16000

Summary

In this example, we deployed a single unsharded keyspace named commerce. Unsharded keyspaces have a single shard named 0. The following schema reflects a common ecommerce scenario that was created by the script:

  1. create table product (
  2. sku varbinary(128),
  3. description varbinary(128),
  4. price bigint,
  5. primary key(sku)
  6. );
  7. create table customer (
  8. customer_id bigint not null auto_increment,
  9. email varbinary(128),
  10. primary key(customer_id)
  11. );
  12. create table corder (
  13. order_id bigint not null auto_increment,
  14. customer_id bigint,
  15. sku varbinary(128),
  16. price bigint,
  17. primary key(order_id)
  18. );

The schema has been simplified to include only those fields that are significant to the example:

  • The product table contains the product information for all of the products.
  • The customer table has a customer_id that has an auto_increment. A typical customer table would have a lot more columns, and sometimes additional detail tables.
  • The corder table (named so because order is an SQL reserved word) has an order_id auto-increment column. It also has foreign keys into customer(customer_id) and product(sku).

Next Steps

You can now proceed with MoveTables.

Or alternatively, once you are finished with the local examples or if you would like to start over, you can clean up by running the 401_teardown script:

  1. $ ./401_teardown.sh
  2. $ rm -rf ./vtdataroot

Sometimes you will still need to manually kill processes if there are errors in the environment:

  1. $ pkill -9 -f ./vtdataroot
  2. $ rm -rf ./vtdataroot