Elastic MySQL connector reference

Elastic MySQL connector reference

The Elastic MySQL connector is a connector for MySQL data sources. This connector is written in Python using the Elastic connector framework.

View the source code for this connector (branch 8.17, compatible with Elastic 8.17).

Choose your connector reference

Are you using a managed connector on Elastic Cloud or a self-managed connector? Expand the documentation based on your deployment method.

Elastic managed connector reference

View Elastic managed connector reference

Availability and prerequisites

This connector is available as a managed connector in Elastic versions 8.5.0 and later. To use this connector natively in Elastic Cloud, satisfy all managed connector requirements.

This connector has no additional prerequisites beyond the shared requirements, linked above.

Compatibility

This connector is compatible with MySQL 5.6 and later.

The connector is also compatible with MariaDB databases compatible with the above.

The data source and your Elastic deployment must be able to communicate with each other over a network.

Create a MySQL connector

Use the UI

To create a new MySQL connector:

  1. In the Kibana UI, navigate to the Search → Content → Connectors page from the main menu, or use the global search field.
  2. Follow the instructions to create a new native MySQL connector.

For additional operations, see Connectors UI in Kibana.

Use the API

You can use the Elasticsearch Create connector API to create a new native MySQL connector.

For example:

  1. resp = client.connector.put(
  2. connector_id="my-{service-name-stub}-connector",
  3. index_name="my-elasticsearch-index",
  4. name="Content synced from {service-name}",
  5. service_type="{service-name-stub}",
  6. is_native=True,
  7. )
  8. print(resp)
  1. const response = await client.connector.put({
  2. connector_id: "my-{service-name-stub}-connector",
  3. index_name: "my-elasticsearch-index",
  4. name: "Content synced from {service-name}",
  5. service_type: "{service-name-stub}",
  6. is_native: true,
  7. });
  8. console.log(response);
  1. PUT _connector/my-mysql-connector
  2. {
  3. "index_name": "my-elasticsearch-index",
  4. "name": "Content synced from MySQL",
  5. "service_type": "mysql",
  6. "is_native": true
  7. }

You’ll also need to create an API key for the connector to use.

The user needs the cluster privileges manage_api_key, manage_connector and write_connector_secrets to generate API keys programmatically.

To create an API key for the connector:

  1. Run the following command, replacing values where indicated. Note the id and encoded return values from the response:

    1. resp = client.security.create_api_key(
    2. name="my-connector-api-key",
    3. role_descriptors={
    4. "my-connector-connector-role": {
    5. "cluster": [
    6. "monitor",
    7. "manage_connector"
    8. ],
    9. "indices": [
    10. {
    11. "names": [
    12. "my-index_name",
    13. ".search-acl-filter-my-index_name",
    14. ".elastic-connectors*"
    15. ],
    16. "privileges": [
    17. "all"
    18. ],
    19. "allow_restricted_indices": False
    20. }
    21. ]
    22. }
    23. },
    24. )
    25. print(resp)
    1. const response = await client.security.createApiKey({
    2. name: "my-connector-api-key",
    3. role_descriptors: {
    4. "my-connector-connector-role": {
    5. cluster: ["monitor", "manage_connector"],
    6. indices: [
    7. {
    8. names: [
    9. "my-index_name",
    10. ".search-acl-filter-my-index_name",
    11. ".elastic-connectors*",
    12. ],
    13. privileges: ["all"],
    14. allow_restricted_indices: false,
    15. },
    16. ],
    17. },
    18. },
    19. });
    20. console.log(response);
    1. POST /_security/api_key
    2. {
    3. "name": "my-connector-api-key",
    4. "role_descriptors": {
    5. "my-connector-connector-role": {
    6. "cluster": [
    7. "monitor",
    8. "manage_connector"
    9. ],
    10. "indices": [
    11. {
    12. "names": [
    13. "my-index_name",
    14. ".search-acl-filter-my-index_name",
    15. ".elastic-connectors*"
    16. ],
    17. "privileges": [
    18. "all"
    19. ],
    20. "allow_restricted_indices": false
    21. }
    22. ]
    23. }
    24. }
    25. }
  2. Use the encoded value to store a connector secret, and note the id return value from this response:

    1. resp = client.perform_request(
    2. "POST",
    3. "/_connector/_secret",
    4. headers={"Content-Type": "application/json"},
    5. body={
    6. "value": "encoded_api_key"
    7. },
    8. )
    9. print(resp)
    1. const response = await client.transport.request({
    2. method: "POST",
    3. path: "/_connector/_secret",
    4. body: {
    5. value: "encoded_api_key",
    6. },
    7. });
    8. console.log(response);
    1. POST _connector/_secret
    2. {
    3. "value": "encoded_api_key"
    4. }
  3. Use the API key id and the connector secret id to update the connector:

    1. resp = client.connector.update_api_key_id(
    2. connector_id="my_connector_id>",
    3. api_key_id="API key_id",
    4. api_key_secret_id="secret_id",
    5. )
    6. print(resp)
    1. const response = await client.connector.updateApiKeyId({
    2. connector_id: "my_connector_id>",
    3. api_key_id: "API key_id",
    4. api_key_secret_id: "secret_id",
    5. });
    6. console.log(response);
    1. PUT /_connector/my_connector_id>/_api_key_id
    2. {
    3. "api_key_id": "API key_id",
    4. "api_key_secret_id": "secret_id"
    5. }

Refer to the Elasticsearch API documentation for details of all available Connector APIs.

Usage

To use this connector natively in Elastic Cloud, see Elastic managed connectors.

For additional operations, see Connectors UI in Kibana.

Configuration

Each time you create an index to be managed by this connector, you will create a new connector configuration. You will need some or all of the following information about the data source.

Host

The IP address or domain name of the MySQL host, excluding port. Examples:

  • 192.158.1.38
  • localhost

Port

The port of the MySQL host. Examples:

  • 3306
  • 3307

Username

The MySQL username the connector will use.

The user must have access to the configured database. You may want to create a dedicated, read-only user for each connector.

Password

The MySQL password the connector will use.

Database

The MySQL database to sync. The database must be accessible using the configured username and password.

Examples:

  • products
  • orders

Comma-separated list of tables

The tables in the configured database to sync. One or more table names, separated by commas. The tables must be accessible using the configured username and password.

Examples:

  • furniture, food, toys
  • laptops

    This field can be bypassed when using advanced sync rules.

Enable SSL

Whether SSL verification will be enabled. Default value is True.

SSL Certificate

Content of SSL certificate. If SSL is disabled, the SSL certificate value will be ignored.

Expand to see an example certificate

  1. -----BEGIN CERTIFICATE-----
  2. MIID+jCCAuKgAwIBAgIGAJJMzlxLMA0GCSqGSIb3DQEBCwUAMHoxCzAJBgNVBAYT
  3. AlVTMQwwCgYDVQQKEwNJQk0xFjAUBgNVBAsTDURlZmF1bHROb2RlMDExFjAUBgNV
  4. BAsTDURlZmF1bHRDZWxsMDExGTAXBgNVBAsTEFJvb3QgQ2VydGlmaWNhdGUxEjAQ
  5. BgNVBAMTCWxvY2FsaG9zdDAeFw0yMTEyMTQyMjA3MTZaFw0yMjEyMTQyMjA3MTZa
  6. MF8xCzAJBgNVBAYTAlVTMQwwCgYDVQQKEwNJQk0xFjAUBgNVBAsTDURlZmF1bHRO
  7. b2RlMDExFjAUBgNVBAsTDURlZmF1bHRDZWxsMDExEjAQBgNVBAMTCWxvY2FsaG9z
  8. dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMv5HCsJZIpI5zCy+jXV
  9. z6lmzNc9UcVSEEHn86h6zT6pxuY90TYeAhlZ9hZ+SCKn4OQ4GoDRZhLPTkYDt+wW
  10. CV3NTIy9uCGUSJ6xjCKoxClJmgSQdg5m4HzwfY4ofoEZ5iZQ0Zmt62jGRWc0zuxj
  11. hegnM+eO2reBJYu6Ypa9RPJdYJsmn1RNnC74IDY8Y95qn+WZj//UALCpYfX41hko
  12. i7TWD9GKQO8SBmAxhjCDifOxVBokoxYrNdzESl0LXvnzEadeZTd9BfUtTaBHhx6t
  13. njqqCPrbTY+3jAbZFd4RiERPnhLVKMytw5ot506BhPrUtpr2lusbN5svNXjuLeea
  14. MMUCAwEAAaOBoDCBnTATBgNVHSMEDDAKgAhOatpLwvJFqjAdBgNVHSUEFjAUBggr
  15. BgEFBQcDAQYIKwYBBQUHAwIwVAYDVR0RBE0wS4E+UHJvZmlsZVVVSUQ6QXBwU3J2
  16. MDEtQkFTRS05MDkzMzJjMC1iNmFiLTQ2OTMtYWI5NC01Mjc1ZDI1MmFmNDiCCWxv
  17. Y2FsaG9zdDARBgNVHQ4ECgQITzqhA5sO8O4wDQYJKoZIhvcNAQELBQADggEBAKR0
  18. gY/BM69S6BDyWp5dxcpmZ9FS783FBbdUXjVtTkQno+oYURDrhCdsfTLYtqUlP4J4
  19. CHoskP+MwJjRIoKhPVQMv14Q4VC2J9coYXnePhFjE+6MaZbTjq9WaekGrpKkMaQA
  20. iQt5b67jo7y63CZKIo9yBvs7sxODQzDn3wZwyux2vPegXSaTHR/rop/s/mPk3YTS
  21. hQprs/IVtPoWU4/TsDN3gIlrAYGbcs29CAt5q9MfzkMmKsuDkTZD0ry42VjxjAmk
  22. xw23l/k8RoD1wRWaDVbgpjwSzt+kl+vJE/ip2w3h69eEZ9wbo6scRO5lCO2JM4Pr
  23. 7RhLQyWn2u00L7/9Omw=
  24. -----END CERTIFICATE-----
Known issues

This connector has the following known issues:

  • Upgrading from a tech preview connector (8.7 or earlier) to 8.8 will cause the MySQL connector configuration to be invalid.

    MySQL connectors prior to 8.8 can be missing some configuration fields that are required for the connector to run. If you would like to continue using your MySQL connector after upgrading from 8.7 or earlier, run the script below to fix your connector’s configuration. This will populate the configuration with the missing fields. The auxilliary information needed for the configuration will then be automatically added by by the self-managed connector.

    1. resp = client.update(
    2. index=".elastic-connectors",
    3. id="connector_id",
    4. doc={
    5. "configuration": {
    6. "tables": {
    7. "type": "list",
    8. "value": "*"
    9. },
    10. "ssl_enabled": {
    11. "type": "bool",
    12. "value": False
    13. },
    14. "ssl_ca": {
    15. "type": "str",
    16. "value": ""
    17. },
    18. "fetch_size": {
    19. "type": "int",
    20. "value": 50
    21. },
    22. "retry_count": {
    23. "type": "int",
    24. "value": 3
    25. }
    26. }
    27. },
    28. )
    29. print(resp)
    1. const response = await client.update({
    2. index: ".elastic-connectors",
    3. id: "connector_id",
    4. doc: {
    5. configuration: {
    6. tables: {
    7. type: "list",
    8. value: "*",
    9. },
    10. ssl_enabled: {
    11. type: "bool",
    12. value: false,
    13. },
    14. ssl_ca: {
    15. type: "str",
    16. value: "",
    17. },
    18. fetch_size: {
    19. type: "int",
    20. value: 50,
    21. },
    22. retry_count: {
    23. type: "int",
    24. value: 3,
    25. },
    26. },
    27. },
    28. });
    29. console.log(response);
    1. POST /.elastic-connectors/_update/connector_id
    2. {
    3. "doc" : {
    4. "configuration": {
    5. "tables": {
    6. "type": "list",
    7. "value": "*"
    8. },
    9. "ssl_enabled": {
    10. "type": "bool",
    11. "value": false
    12. },
    13. "ssl_ca": {
    14. "type": "str",
    15. "value": ""
    16. },
    17. "fetch_size": {
    18. "type": "int",
    19. "value": 50
    20. },
    21. "retry_count": {
    22. "type": "int",
    23. "value": 3
    24. }
    25. }
    26. }
    27. }
  • Upgrading to 8.8 does not migrate MySQL sync rules.

    After upgrading, you must re-create your sync rules.

See Known issues for any issues affecting all connectors.

Documents and syncs

The following describes the default syncing behavior for this connector. Use sync rules and ingest pipelines to customize syncing for specific indices.

All records in the MySQL database included in your connector configuration are extracted and transformed into documents in your Elasticsearch index.

  • For each row in your MySQL database table, the connector creates one Elasticsearch document.
  • For each column, the connector transforms the column into an Elasticsearch field.
  • Elasticsearch dynamically maps MySQL data types to Elasticsearch data types.
  • Tables with no primary key defined are skipped.
  • Field values that represent other records are replaced with the primary key for that record (composite primary keys are joined with _).

The Elasticsearch mapping is created when the first document is created.

Each sync is a “full” sync.

For each MySQL row discovered:

  • If it does not exist, the document is created in Elasticsearch.
  • If it already exists in Elasticsearch, the Elasticsearch document is replaced and the version is incremented.
  • If an existing Elasticsearch document no longer exists in the MySQL table, it is deleted from Elasticsearch.

  • Files bigger than 10 MB won’t be extracted

  • Permissions are not synced by default. All documents indexed to an Elastic deployment will be visible to all users with access to that Elastic Deployment.
Sync rules

The following sections describe Sync rules for this connector.

Basic sync rules are identical for all connectors and are available by default.

Advanced rules for MySQL can be used to pass arbitrary SQL statements to a MySQL instance.

You need to specify the tables used in your custom query in the “tables” field.

For example:

  1. [
  2. {
  3. "tables": ["table1", "table2"],
  4. "query": "SELECT ... FROM ..."
  5. }
  6. ]

When using advanced rules, a query can bypass the configuration field tables. This will happen if the query specifies a table that doesn’t appear in the configuration. This can also happen if the configuration specifies * to fetch all tables while the advanced sync rule requests for only a subset of tables.

Troubleshooting

See Troubleshooting.

Security

See Security.

Self-managed connector

View self-managed connector reference

Availability and prerequisites

This connector is available as a managed connector in Elastic versions 8.5.0 and later. To use this connector natively in Elastic Cloud, satisfy all managed connector requirements.

This connector is also available as a self-managed connector from the Elastic connector framework. To use this connector as a self-managed connector, satisfy all self-managed connector requirements.

This connector has no additional prerequisites beyond the shared requirements, linked above.

Create a MySQL connector

Use the UI

To create a new MySQL connector:

  1. In the Kibana UI, navigate to the Search → Content → Connectors page from the main menu, or use the global search field.
  2. Follow the instructions to create a new MySQL self-managed connector.

Use the API

You can use the Elasticsearch Create connector API to create a new self-managed MySQL self-managed connector.

For example:

  1. resp = client.connector.put(
  2. connector_id="my-{service-name-stub}-connector",
  3. index_name="my-elasticsearch-index",
  4. name="Content synced from {service-name}",
  5. service_type="{service-name-stub}",
  6. )
  7. print(resp)
  1. const response = await client.connector.put({
  2. connector_id: "my-{service-name-stub}-connector",
  3. index_name: "my-elasticsearch-index",
  4. name: "Content synced from {service-name}",
  5. service_type: "{service-name-stub}",
  6. });
  7. console.log(response);
  1. PUT _connector/my-mysql-connector
  2. {
  3. "index_name": "my-elasticsearch-index",
  4. "name": "Content synced from MySQL",
  5. "service_type": "mysql"
  6. }

You’ll also need to create an API key for the connector to use.

The user needs the cluster privileges manage_api_key, manage_connector and write_connector_secrets to generate API keys programmatically.

To create an API key for the connector:

  1. Run the following command, replacing values where indicated. Note the encoded return values from the response:

    1. resp = client.security.create_api_key(
    2. name="connector_name-connector-api-key",
    3. role_descriptors={
    4. "connector_name-connector-role": {
    5. "cluster": [
    6. "monitor",
    7. "manage_connector"
    8. ],
    9. "indices": [
    10. {
    11. "names": [
    12. "index_name",
    13. ".search-acl-filter-index_name",
    14. ".elastic-connectors*"
    15. ],
    16. "privileges": [
    17. "all"
    18. ],
    19. "allow_restricted_indices": False
    20. }
    21. ]
    22. }
    23. },
    24. )
    25. print(resp)
    1. const response = await client.security.createApiKey({
    2. name: "connector_name-connector-api-key",
    3. role_descriptors: {
    4. "connector_name-connector-role": {
    5. cluster: ["monitor", "manage_connector"],
    6. indices: [
    7. {
    8. names: [
    9. "index_name",
    10. ".search-acl-filter-index_name",
    11. ".elastic-connectors*",
    12. ],
    13. privileges: ["all"],
    14. allow_restricted_indices: false,
    15. },
    16. ],
    17. },
    18. },
    19. });
    20. console.log(response);
    1. POST /_security/api_key
    2. {
    3. "name": "connector_name-connector-api-key",
    4. "role_descriptors": {
    5. "connector_name-connector-role": {
    6. "cluster": [
    7. "monitor",
    8. "manage_connector"
    9. ],
    10. "indices": [
    11. {
    12. "names": [
    13. "index_name",
    14. ".search-acl-filter-index_name",
    15. ".elastic-connectors*"
    16. ],
    17. "privileges": [
    18. "all"
    19. ],
    20. "allow_restricted_indices": false
    21. }
    22. ]
    23. }
    24. }
    25. }
  2. Update your config.yml file with the API key encoded value.

Refer to the Elasticsearch API documentation for details of all available Connector APIs.

Usage

To use this connector as a managed connector, use the Connector workflow. See Elastic managed connectors.

To use this connector as a self-managed connector, see Self-managed connectors.

For additional operations, see Connectors UI in Kibana.

Compatibility

This connector is compatible with MySQL 5.6 and later.

The connector is also compatible with MariaDB databases compatible with the above.

The data source and your Elastic deployment must be able to communicate with each other over a network.

Configuration

Each time you create an index to be managed by this connector, you will create a new connector configuration. You will need some or all of the following information about the data source.

Host

The IP address or domain name of the MySQL host, excluding port. Examples:

  • 192.158.1.38
  • localhost

Port

The port of the MySQL host. Examples:

  • 3306
  • 3307

Username

The MySQL username the connector will use.

The user must have access to the configured database. You may want to create a dedicated, read-only user for each connector.

Password

The MySQL password the connector will use.

Database

The MySQL database to sync. The database must be accessible using the configured username and password.

Examples:

  • products
  • orders

Tables

The tables in the configured database to sync. One or more table names, separated by commas. The tables must be accessible using the configured username and password.

Examples:

  • furniture, food, toys
  • laptops

Enable SSL

Whether SSL verification will be enabled. Default value is True.

SSL Certificate

Content of SSL certificate. If SSL is disabled, the SSL certificate value will be ignored.

Expand to see an example certificate

  1. -----BEGIN CERTIFICATE-----
  2. MIID+jCCAuKgAwIBAgIGAJJMzlxLMA0GCSqGSIb3DQEBCwUAMHoxCzAJBgNVBAYT
  3. AlVTMQwwCgYDVQQKEwNJQk0xFjAUBgNVBAsTDURlZmF1bHROb2RlMDExFjAUBgNV
  4. BAsTDURlZmF1bHRDZWxsMDExGTAXBgNVBAsTEFJvb3QgQ2VydGlmaWNhdGUxEjAQ
  5. BgNVBAMTCWxvY2FsaG9zdDAeFw0yMTEyMTQyMjA3MTZaFw0yMjEyMTQyMjA3MTZa
  6. MF8xCzAJBgNVBAYTAlVTMQwwCgYDVQQKEwNJQk0xFjAUBgNVBAsTDURlZmF1bHRO
  7. b2RlMDExFjAUBgNVBAsTDURlZmF1bHRDZWxsMDExEjAQBgNVBAMTCWxvY2FsaG9z
  8. dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMv5HCsJZIpI5zCy+jXV
  9. z6lmzNc9UcVSEEHn86h6zT6pxuY90TYeAhlZ9hZ+SCKn4OQ4GoDRZhLPTkYDt+wW
  10. CV3NTIy9uCGUSJ6xjCKoxClJmgSQdg5m4HzwfY4ofoEZ5iZQ0Zmt62jGRWc0zuxj
  11. hegnM+eO2reBJYu6Ypa9RPJdYJsmn1RNnC74IDY8Y95qn+WZj//UALCpYfX41hko
  12. i7TWD9GKQO8SBmAxhjCDifOxVBokoxYrNdzESl0LXvnzEadeZTd9BfUtTaBHhx6t
  13. njqqCPrbTY+3jAbZFd4RiERPnhLVKMytw5ot506BhPrUtpr2lusbN5svNXjuLeea
  14. MMUCAwEAAaOBoDCBnTATBgNVHSMEDDAKgAhOatpLwvJFqjAdBgNVHSUEFjAUBggr
  15. BgEFBQcDAQYIKwYBBQUHAwIwVAYDVR0RBE0wS4E+UHJvZmlsZVVVSUQ6QXBwU3J2
  16. MDEtQkFTRS05MDkzMzJjMC1iNmFiLTQ2OTMtYWI5NC01Mjc1ZDI1MmFmNDiCCWxv
  17. Y2FsaG9zdDARBgNVHQ4ECgQITzqhA5sO8O4wDQYJKoZIhvcNAQELBQADggEBAKR0
  18. gY/BM69S6BDyWp5dxcpmZ9FS783FBbdUXjVtTkQno+oYURDrhCdsfTLYtqUlP4J4
  19. CHoskP+MwJjRIoKhPVQMv14Q4VC2J9coYXnePhFjE+6MaZbTjq9WaekGrpKkMaQA
  20. iQt5b67jo7y63CZKIo9yBvs7sxODQzDn3wZwyux2vPegXSaTHR/rop/s/mPk3YTS
  21. hQprs/IVtPoWU4/TsDN3gIlrAYGbcs29CAt5q9MfzkMmKsuDkTZD0ry42VjxjAmk
  22. xw23l/k8RoD1wRWaDVbgpjwSzt+kl+vJE/ip2w3h69eEZ9wbo6scRO5lCO2JM4Pr
  23. 7RhLQyWn2u00L7/9Omw=
  24. -----END CERTIFICATE-----
Known issues

This connector has the following known issues:

  • Upgrading from a tech preview connector (8.7 or earlier) to 8.8 will cause the MySQL connector configuration to be invalid.

    MySQL connectors prior to 8.8 can be missing some configuration fields that are required for the connector to run. If you would like to continue using your MySQL connector after upgrading from 8.7 or earlier, run the script below to fix your connector’s configuration. This will populate the configuration with the missing fields. The auxilliary information needed for the configuration will then be automatically added by by the self-managed connector.

    1. resp = client.update(
    2. index=".elastic-connectors",
    3. id="connector_id",
    4. doc={
    5. "configuration": {
    6. "tables": {
    7. "type": "list",
    8. "value": "*"
    9. },
    10. "ssl_enabled": {
    11. "type": "bool",
    12. "value": False
    13. },
    14. "ssl_ca": {
    15. "type": "str",
    16. "value": ""
    17. },
    18. "fetch_size": {
    19. "type": "int",
    20. "value": 50
    21. },
    22. "retry_count": {
    23. "type": "int",
    24. "value": 3
    25. }
    26. }
    27. },
    28. )
    29. print(resp)
    1. const response = await client.update({
    2. index: ".elastic-connectors",
    3. id: "connector_id",
    4. doc: {
    5. configuration: {
    6. tables: {
    7. type: "list",
    8. value: "*",
    9. },
    10. ssl_enabled: {
    11. type: "bool",
    12. value: false,
    13. },
    14. ssl_ca: {
    15. type: "str",
    16. value: "",
    17. },
    18. fetch_size: {
    19. type: "int",
    20. value: 50,
    21. },
    22. retry_count: {
    23. type: "int",
    24. value: 3,
    25. },
    26. },
    27. },
    28. });
    29. console.log(response);
    1. POST /.elastic-connectors/_update/connector_id
    2. {
    3. "doc" : {
    4. "configuration": {
    5. "tables": {
    6. "type": "list",
    7. "value": "*"
    8. },
    9. "ssl_enabled": {
    10. "type": "bool",
    11. "value": false
    12. },
    13. "ssl_ca": {
    14. "type": "str",
    15. "value": ""
    16. },
    17. "fetch_size": {
    18. "type": "int",
    19. "value": 50
    20. },
    21. "retry_count": {
    22. "type": "int",
    23. "value": 3
    24. }
    25. }
    26. }
    27. }
  • Upgrading to 8.8 does not migrate MySQL sync rules.

    After upgrading, you must re-create your sync rules.

See Known issues for any issues affecting all connectors.

Documents and syncs

The following describes the default syncing behavior for this connector. Use sync rules and ingest pipelines to customize syncing for specific indices.

All records in the MySQL database included in your connector configuration are extracted and transformed into documents in your Elasticsearch index.

  • For each row in your MySQL database table, the connector creates one Elasticsearch document.
  • For each column, the connector transforms the column into an Elasticsearch field.
  • Elasticsearch dynamically maps MySQL data types to Elasticsearch data types.
  • Tables with no primary key defined are skipped.
  • Field values that represent other records are replaced with the primary key for that record (composite primary keys are joined with _).

The Elasticsearch mapping is created when the first document is created.

Each sync is a “full” sync.

For each MySQL row discovered:

  • If it does not exist, the document is created in Elasticsearch.
  • If it already exists in Elasticsearch, the Elasticsearch document is replaced and the version is incremented.
  • If an existing Elasticsearch document no longer exists in the MySQL table, it is deleted from Elasticsearch.
Deployment using Docker

You can deploy the MySQL connector as a self-managed connector using Docker. Follow these instructions.

Step 1: Download sample configuration file

Download the sample configuration file. You can either download it manually or run the following command:

  1. curl https://raw.githubusercontent.com/elastic/connectors/main/config.yml.example --output ~/connectors-config/config.yml

Remember to update the --output argument value if your directory name is different, or you want to use a different config file name.

Step 2: Update the configuration file for your self-managed connector

Update the configuration file with the following settings to match your environment:

  • elasticsearch.host
  • elasticsearch.api_key
  • connectors

If you’re running the connector service against a Dockerized version of Elasticsearch and Kibana, your config file will look like this:

  1. # When connecting to your cloud deployment you should edit the host value
  2. elasticsearch.host: http://host.docker.internal:9200
  3. elasticsearch.api_key: <ELASTICSEARCH_API_KEY>
  4. connectors:
  5. -
  6. connector_id: <CONNECTOR_ID_FROM_KIBANA>
  7. service_type: mysql
  8. api_key: <CONNECTOR_API_KEY_FROM_KIBANA> # Optional. If not provided, the connector will use the elasticsearch.api_key instead

Using the elasticsearch.api_key is the recommended authentication method. However, you can also use elasticsearch.username and elasticsearch.password to authenticate with your Elasticsearch instance.

Note: You can change other default configurations by simply uncommenting specific settings in the configuration file and modifying their values.

Step 3: Run the Docker image

Run the Docker image with the Connector Service using the following command:

  1. docker run \
  2. -v ~/connectors-config:/config \
  3. --network "elastic" \
  4. --tty \
  5. --rm \
  6. docker.elastic.co/enterprise-search/elastic-connectors:8.17.0.0 \
  7. /app/bin/elastic-ingest \
  8. -c /config/config.yml

Refer to DOCKER.md in the elastic/connectors repo for more details.

Find all available Docker images in the official registry.

We also have a quickstart self-managed option using Docker Compose, so you can spin up all required services at once: Elasticsearch, Kibana, and the connectors service. Refer to this README in the elastic/connectors repo for more information.

Sync rules

The following sections describe Sync rules for this connector.

Basic sync rules are identical for all connectors and are available by default.

Advanced rules for MySQL can be used to pass arbitrary SQL statements to a MySQL instance.

You need to specify the tables used in your custom query in the “tables” field.

For example:

  1. [
  2. {
  3. "tables": ["table1", "table2"],
  4. "query": "SELECT ... FROM ..."
  5. }
  6. ]

When using advanced rules, a query can bypass the configuration field tables. This will happen if the query specifies a table that doesn’t appear in the configuration. This can also happen if the configuration specifies * to fetch all tables while the advanced sync rule requests for only a subset of tables.

Troubleshooting

See Troubleshooting.

Security

See Security.