Local Install via Homebrew

Instructions for using Vitess on your macOS machine for testing purposes

This guide covers installing Vitess locally to macOS 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 Homebrew package manager is also available, which requires no dependencies on your local host.

  1. /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

In this guide, v9.0.0 is used in most outputs. You can replace it by the version of Vitess you are using.

Install Vitess with Homebrew

Vitess supports the databases listed here. Homebrew will install latest tagged Vitess Release.

  1. $ brew install vitess
  2. Updating Homebrew...
  3. ==> Auto-updated Homebrew!
  4. Updated 2 taps (homebrew/core and homebrew/cask).
  5. ==> Updated Formulae
  6. Updated 19 formulae.
  7. ==> Updated Casks
  8. Updated 1 cask.
  9. ==> Downloading https://homebrew.bintray.com/bottles/vitess-9.0.0.catalina.bottle.tar.gz
  10. Already downloaded: /Users/askdba/Library/Caches/Homebrew/downloads/45991b27589a191910e89a1ce529fcdaa694bb5f36b99f1b20146f8f0fc3ee6d--vitess-9.0.0.catalina.bottle.tar.gz
  11. ==> Pouring vitess-9.0.0.catalina.bottle.tar.gz
  12. 🍺 /usr/local/Cellar/vitess/9.0.0: 268 files, 528.3MB

At this point Vitess binaries installed under default Homebrew install location at /usr/local/share/vitess.

Install Node 16.13.0+ (required to run VTAdmin)

  1. $ brew install nvm
  2. $ nvm install --lts 16.13.0
  3. $ nvm use 16.13.0

See the vtadmin README for more details.

Start a Single Keyspace Cluster

For testing purposes initiate following example;

  1. $ cd /usr/local/share/vitess/examples/local/
  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. Starting MySQL for tablet zone1-0000000100...
  11. Starting vttablet for zone1-0000000100...
  12. HTTP/1.1 200 OK
  13. Date: Thu, 01 Sep 2022 12:49:50 GMT
  14. Content-Type: text/html; charset=utf-8
  15. Starting MySQL for tablet zone1-0000000101...
  16. Starting vttablet for zone1-0000000101...
  17. HTTP/1.1 200 OK
  18. Date: Thu, 01 Sep 2022 12:49:55 GMT
  19. Content-Type: text/html; charset=utf-8
  20. Starting MySQL for tablet zone1-0000000102...
  21. Starting vttablet for zone1-0000000102...
  22. HTTP/1.1 200 OK
  23. Date: Thu, 01 Sep 2022 12:50:00 GMT
  24. Content-Type: text/html; charset=utf-8
  25. {
  26. "keyspace": {
  27. "served_froms": [],
  28. "keyspace_type": 0,
  29. "base_keyspace": "",
  30. "snapshot_time": null,
  31. "durability_policy": "semi_sync",
  32. "throttler_config": null,
  33. "sidecar_db_name": "_vt"
  34. }
  35. }
  36. vtorc is running!
  37. - UI: http://localhost:16000
  38. - Logs: /Users/manangupta/vitess/vtdataroot/tmp/vtorc.out
  39. - PID: 74088
  40. zone1-0000000100 commerce 0 primary localhost:15100 localhost:17100 [] 2022-09-23T05:48:52Z
  41. New VSchema object:
  42. {
  43. "sharded": false,
  44. "vindexes": {},
  45. "tables": {
  46. "corder": {
  47. "type": "",
  48. "column_vindexes": [],
  49. "auto_increment": null,
  50. "columns": [],
  51. "pinned": "",
  52. "column_list_authoritative": false
  53. },
  54. "customer": {
  55. "type": "",
  56. "column_vindexes": [],
  57. "auto_increment": null,
  58. "columns": [],
  59. "pinned": "",
  60. "column_list_authoritative": false
  61. },
  62. "product": {
  63. "type": "",
  64. "column_vindexes": [],
  65. "auto_increment": null,
  66. "columns": [],
  67. "pinned": "",
  68. "column_list_authoritative": false
  69. }
  70. },
  71. "require_explicit_routing": false
  72. }
  73. If this is not what you expected, check the input data (as JSON parsing will skip unexpected fields).
  74. Waiting for vtgate to be up...
  75. vtgate is up!
  76. Access vtgate at http://Manans-MacBook-Pro.local:15001/debug/status
  77. vtadmin-api is running!
  78. - API: http://localhost:14200
  79. - Logs: /Users/manangupta/vitess/vtdataroot/tmp/vtadmin-api.out
  80. - PID: 74039
  81. > vtadmin@0.1.0 build
  82. > vite build
  83. vite v4.2.1 building for production...
  84. transforming (1218) src/icons/alertFail.svgUse of eval in "node_modules/@protobufjs/inquire/index.js" is strongly discouraged as it poses security risks and may cause issues with minification.
  85. 1231 modules transformed.
  86. build/assets/chevronUp-3d6782a5.svg 0.18 kB
  87. build/assets/chevronDown-02f94e73.svg 0.19 kB
  88. build/assets/download-8ef290b4.svg 0.21 kB
  89. build/assets/delete-a9184ef9.svg 0.23 kB
  90. build/assets/info-2617ee9d.svg 0.34 kB
  91. build/assets/circleAdd-cfd7e5db.svg 0.35 kB
  92. build/assets/alertFail-8056b6e4.svg 0.35 kB
  93. build/assets/checkSuccess-f8fd1dbb.svg 0.36 kB
  94. build/assets/search-3261bac7.svg 0.41 kB
  95. build/assets/question-a67b2492.svg 0.46 kB
  96. build/assets/runQuery-edfab4ed.svg 0.49 kB
  97. build/assets/open-405dd348.svg 0.49 kB
  98. build/index.html 0.90 kB
  99. build/assets/bug-5b6edb54.svg 0.99 kB
  100. build/assets/topology-0032b65e.svg 1.62 kB
  101. build/assets/NotoMono-Regular-41fd7ccc.ttf 107.85 kB
  102. build/assets/NotoSans-Regular-c8cff31f.ttf 313.14 kB
  103. build/assets/NotoSans-SemiBold-43207822.ttf 313.72 kB
  104. build/assets/NotoSans-Bold-c6a598dd.ttf 313.79 kB
  105. build/assets/index-ef40fbc9.css 87.78 kB gzip: 15.02 kB
  106. build/assets/index-4ddb52ed.js 2,811.88 kB gzip: 492.59 kB
  107. (!) Some chunks are larger than 500 kBs after minification. Consider:
  108. - Using dynamic import() to code-split the application
  109. - Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
  110. - Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
  111. built in 10.85s
  112. vtadmin-web is running!
  113. - Browser: http://localhost:14201
  114. - Logs: /Users/manangupta/vitess/vtdataroot/tmp/vtadmin-web.out
  115. - PID: 74070

Verify your initial cluster:

  1. $ mysql -e "show vitess_tablets"
  2. +-------+----------+-------+------------+---------+------------------+-----------+----------------------+
  3. | Cell | Keyspace | Shard | TabletType | State | Alias | Hostname | MasterTermStartTime |
  4. +-------+----------+-------+------------+---------+------------------+-----------+----------------------+
  5. | zone1 | commerce | 0 | PRIMARY | SERVING | zone1-0000000100 | localhost | 2021-02-17T13:10:13Z |
  6. | zone1 | commerce | 0 | REPLICA | SERVING | zone1-0000000101 | localhost | |
  7. | zone1 | commerce | 0 | RDONLY | SERVING | zone1-0000000102 | localhost | |
  8. +-------+----------+-------+------------+---------+------------------+-----------+----------------------+

You can also verify that the processes have started with pgrep:

  1. $ pgrep -fl vitess | awk '{print $2,$3}'
  2. etcd --enable-v2=true
  3. vtctld -topo_implementation
  4. /bin/sh /usr/local/opt/mysql@5.7/bin/mysqld_safe
  5. /usr/local/opt/mysql@5.7/bin/mysqld --defaults-file=/usr/local/Cellar/vitess/9.0.0/share/vitess/examples/local/vtdataroot/vt_0000000100/my.cnf
  6. vttablet -topo_implementation
  7. /bin/sh /usr/local/opt/mysql@5.7/bin/mysqld_safe
  8. /usr/local/opt/mysql@5.7/bin/mysqld --defaults-file=/usr/local/Cellar/vitess/9.0.0/share/vitess/examples/local/vtdataroot/vt_0000000101/my.cnf
  9. vttablet -topo_implementation
  10. /bin/sh /usr/local/opt/mysql@5.7/bin/mysqld_safe
  11. /usr/local/opt/mysql@5.7/bin/mysqld --defaults-file=/usr/local/Cellar/vitess/9.0.0/share/vitess/examples/local/vtdataroot/vt_0000000102/my.cnf
  12. vttablet -topo_implementation
  13. vtgate -topo_implementation
  14. vtorc --topo_implementation

The exact list of processes will vary. For example, you may not see mysqld_safe listed.

If you encounter any errors, such as ports already in use, you can kill the processes and start over:

  1. pkill -9 -f '(vtdataroot|VTDATAROOT|vitess|vtadmin)' # kill Vitess processes
  2. rm -rf /usr/local/Cellar/vitess/9.0.0/share/vitess/examples/local/vtdataroot

Setup Aliases

For ease-of-use, Vitess provides aliases for mysql and vtctlclient:

  1. source ./env.sh

Setting up aliases changes mysql to always connect to Vitess for your current session. To revert this, type unalias mysql && unalias vtctlclient or close your session.

Connect to your cluster

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

  1. /usr/local/share/vitess/examples/local> mysql
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 2
  4. Server version: 5.7.9-Vitess (Ubuntu)
  5. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10. mysql> show tables;
  11. +-----------------------+
  12. | Tables_in_vt_commerce |
  13. +-----------------------+
  14. | corder |
  15. | customer |
  16. | product |
  17. +-----------------------+
  18. 3 rows in set (0.00 sec)

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, if you would like to teardown your example:

  1. pkill -9 -f '(vtdataroot|VTDATAROOT)' # kill Vitess processes
  2. rm -rf /usr/local/Cellar/vitess/9.0.0/share/vitess/examples/local/vtdataroot