use-ssh-tunnel.html 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 1. In the [SQL Shell](https://console.materialize.com/), or your preferred SQL
  2. client connected to Materialize, use the [`CREATE CONNECTION`](/sql/create-connection/#ssh-tunnel)
  3. command to create an SSH tunnel connection:
  4. ```mzsql
  5. CREATE CONNECTION ssh_connection TO SSH TUNNEL (
  6. HOST '<SSH_BASTION_HOST>',
  7. PORT <SSH_BASTION_PORT>,
  8. USER '<SSH_BASTION_USER>'
  9. );
  10. ```
  11. - Replace `<SSH_BASTION_HOST>` and `<SSH_BASTION_PORT`> with the public IP address and port of the SSH bastion host you created [earlier](#b-optional-configure-network-security).
  12. - Replace `<SSH_BASTION_USER>` with the username for the key pair you created for your SSH bastion host.
  13. 1. Get Materialize's public keys for the SSH tunnel connection:
  14. ```mzsql
  15. SELECT * FROM mz_ssh_tunnel_connections;
  16. ```
  17. 1. Log in to your SSH bastion host and add Materialize's public keys to the `authorized_keys` file, for example:
  18. ```sh
  19. # Command for Linux
  20. echo "ssh-ed25519 AAAA...76RH materialize" >> ~/.ssh/authorized_keys
  21. echo "ssh-ed25519 AAAA...hLYV materialize" >> ~/.ssh/authorized_keys
  22. ```
  23. 1. Back in the SQL client connected to Materialize, validate the SSH tunnel connection you created using the [`VALIDATE CONNECTION`](/sql/validate-connection) command:
  24. ```mzsql
  25. VALIDATE CONNECTION ssh_connection;
  26. ```
  27. If no validation error is returned, move to the next step.
  28. 1. Use the [`CREATE SECRET`](/sql/create-secret/) command to securely store the password for the `materialize` SQL Server user [you created](#1-create-a-materialize-user-in-sql-server):
  29. ```mzsql
  30. CREATE SECRET sql_server_pass AS '<PASSWORD>';
  31. ```
  32. For AWS IAM authentication, you must create a connection to AWS. See the [`CREATE CONNECTION`](/sql/create-connection/#aws) command for details.
  33. 1. Use the [`CREATE CONNECTION`](/sql/create-connection/) command to create another connection object, this time with database access and authentication details for Materialize to use:
  34. ```mzsql
  35. CREATE CONNECTION sql_server_connection TO SQL SERVER (
  36. HOST '<host>',
  37. SSH TUNNEL ssh_connection
  38. );
  39. ```
  40. - Replace `<host>` with your SQL Server endpoint.
  41. 1. Use the [`CREATE SOURCE`](/sql/create-source/) command to connect Materialize to your SQL Server instance and start ingesting data:
  42. ```mzsql
  43. CREATE SOURCE mz_source
  44. FROM SQL SERVER CONNECTION sql_server_connection
  45. FOR ALL TABLES;
  46. ```
  47. - By default, the source will be created in the active cluster; to use a
  48. different cluster, use the `IN CLUSTER` clause.
  49. - To ingest data from specific schemas or tables, use the `FOR SCHEMAS
  50. (<schema1>,<schema2>)` or `FOR TABLES (<table1>, <table2>)` options
  51. instead of `FOR ALL TABLES`.
  52. - To handle unsupported data types, use the `TEXT COLUMNS` or `IGNORE
  53. COLUMNS` options. Check out the [reference documentation](/sql/create-source/sql-server/#supported-types)
  54. for guidance.