use-ssh-tunnel.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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` MySQL user you created [earlier](#2-create-a-user-for-replication):
  29. ```mzsql
  30. CREATE SECRET mysqlpass 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 mysql_connection TO MYSQL (
  36. HOST '<host>',
  37. SSH TUNNEL ssh_connection
  38. );
  39. ```
  40. - Replace `<host>` with your MySQL endpoint.
  41. AWS IAM authentication is also available, see the [`CREATE CONNECTION`](/sql/create-connection/#mysql)
  42. command for details.
  43. 1. Use the [`CREATE SOURCE`](/sql/create-source/) command to connect Materialize to your MySQL instance and start ingesting data:
  44. ```mzsql
  45. CREATE SOURCE mz_source
  46. FROM mysql CONNECTION mysql_connection
  47. FOR ALL TABLES;
  48. ```
  49. - By default, the source will be created in the active cluster; to use a
  50. different cluster, use the `IN CLUSTER` clause.
  51. - To ingest data from specific schemas or tables, use the `FOR SCHEMAS
  52. (<schema1>,<schema2>)` or `FOR TABLES (<table1>, <table2>)` options
  53. instead of `FOR ALL TABLES`.
  54. - To handle unsupported data types, use the `TEXT COLUMNS` or `IGNORE
  55. COLUMNS` options. Check out the [reference documentation](/sql/create-source/mysql/#supported-types)
  56. for guidance.