elasticsearch/docs/reference/connector/docs/connectors-mysql.asciidoc
2024-09-30 19:01:25 +10:00

538 lines
17 KiB
Text

[#es-connectors-mysql]
=== Elastic MySQL connector reference
++++
<titleabbrev>MySQL</titleabbrev>
++++
// Attributes used in this file:
:service-name: MySQL
:service-name-stub: mysql
The _Elastic MySQL connector_ is a <<es-connectors,connector>> for https://www.mysql.com[MySQL^] data sources.
This connector is written in Python using the {connectors-python}[Elastic connector framework^].
View the {connectors-python}/connectors/sources/{service-name-stub}.py[*source code* for this connector^] (branch _{connectors-branch}_, compatible with Elastic _{minor-version}_).
.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.
*******************************
// //////// //// //// //// //// //// //// ////////
// //////// NATIVE CONNECTOR REFERENCE ///////
// //////// //// //// //// //// //// //// ////////
[discrete#es-connectors-mysql-native-connector-reference]
==== *Elastic managed connector reference*
.View *Elastic managed connector* reference
[%collapsible]
===============
[discrete#es-connectors-mysql-prerequisites]
===== 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 <<es-native-connectors,managed connector requirements>>.
This connector has no additional prerequisites beyond the shared requirements, linked above.
[discrete#es-connectors-mysql-compatibility]
===== 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.
[discrete#es-connectors-mysql-create-native-connector]
===== Create a {service-name} connector
include::_connectors-create-native.asciidoc[]
[discrete#es-connectors-mysql-usage]
===== Usage
To use this connector natively in Elastic Cloud, see <<es-native-connectors>>.
For additional operations, see <<es-connectors-usage>>.
[discrete#es-connectors-mysql-configuration]
===== 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`
+
[TIP]
====
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
[%collapsible]
====
```
-----BEGIN CERTIFICATE-----
MIID+jCCAuKgAwIBAgIGAJJMzlxLMA0GCSqGSIb3DQEBCwUAMHoxCzAJBgNVBAYT
AlVTMQwwCgYDVQQKEwNJQk0xFjAUBgNVBAsTDURlZmF1bHROb2RlMDExFjAUBgNV
BAsTDURlZmF1bHRDZWxsMDExGTAXBgNVBAsTEFJvb3QgQ2VydGlmaWNhdGUxEjAQ
BgNVBAMTCWxvY2FsaG9zdDAeFw0yMTEyMTQyMjA3MTZaFw0yMjEyMTQyMjA3MTZa
MF8xCzAJBgNVBAYTAlVTMQwwCgYDVQQKEwNJQk0xFjAUBgNVBAsTDURlZmF1bHRO
b2RlMDExFjAUBgNVBAsTDURlZmF1bHRDZWxsMDExEjAQBgNVBAMTCWxvY2FsaG9z
dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMv5HCsJZIpI5zCy+jXV
z6lmzNc9UcVSEEHn86h6zT6pxuY90TYeAhlZ9hZ+SCKn4OQ4GoDRZhLPTkYDt+wW
CV3NTIy9uCGUSJ6xjCKoxClJmgSQdg5m4HzwfY4ofoEZ5iZQ0Zmt62jGRWc0zuxj
hegnM+eO2reBJYu6Ypa9RPJdYJsmn1RNnC74IDY8Y95qn+WZj//UALCpYfX41hko
i7TWD9GKQO8SBmAxhjCDifOxVBokoxYrNdzESl0LXvnzEadeZTd9BfUtTaBHhx6t
njqqCPrbTY+3jAbZFd4RiERPnhLVKMytw5ot506BhPrUtpr2lusbN5svNXjuLeea
MMUCAwEAAaOBoDCBnTATBgNVHSMEDDAKgAhOatpLwvJFqjAdBgNVHSUEFjAUBggr
BgEFBQcDAQYIKwYBBQUHAwIwVAYDVR0RBE0wS4E+UHJvZmlsZVVVSUQ6QXBwU3J2
MDEtQkFTRS05MDkzMzJjMC1iNmFiLTQ2OTMtYWI5NC01Mjc1ZDI1MmFmNDiCCWxv
Y2FsaG9zdDARBgNVHQ4ECgQITzqhA5sO8O4wDQYJKoZIhvcNAQELBQADggEBAKR0
gY/BM69S6BDyWp5dxcpmZ9FS783FBbdUXjVtTkQno+oYURDrhCdsfTLYtqUlP4J4
CHoskP+MwJjRIoKhPVQMv14Q4VC2J9coYXnePhFjE+6MaZbTjq9WaekGrpKkMaQA
iQt5b67jo7y63CZKIo9yBvs7sxODQzDn3wZwyux2vPegXSaTHR/rop/s/mPk3YTS
hQprs/IVtPoWU4/TsDN3gIlrAYGbcs29CAt5q9MfzkMmKsuDkTZD0ry42VjxjAmk
xw23l/k8RoD1wRWaDVbgpjwSzt+kl+vJE/ip2w3h69eEZ9wbo6scRO5lCO2JM4Pr
7RhLQyWn2u00L7/9Omw=
-----END CERTIFICATE-----
```
====
[discrete#es-connectors-mysql-known-issues]
===== 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.
+
[source,console]
----
POST /.elastic-connectors/_update/connector_id
{
"doc" : {
"configuration": {
"tables": {
"type": "list",
"value": "*"
},
"ssl_enabled": {
"type": "bool",
"value": false
},
"ssl_ca": {
"type": "str",
"value": ""
},
"fetch_size": {
"type": "int",
"value": 50
},
"retry_count": {
"type": "int",
"value": 3
}
}
}
}
----
// TEST[skip:TODO]
+
* *Upgrading to 8.8 does not migrate MySQL sync rules.*
+
After upgrading, you must re-create your sync rules.
See <<es-connectors-known-issues>> for any issues affecting all connectors.
[discrete#es-connectors-mysql-syncs]
===== Documents and syncs
The following describes the default syncing behavior for this connector.
Use <<es-sync-rules,sync rules>> and {ref}/ingest-pipeline-search.html[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 {ref}/dynamic-mapping.html[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.
[NOTE]
====
* 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.
====
[discrete#es-connectors-mysql-sync-rules]
===== Sync rules
The following sections describe <<es-sync-rules>> for this connector.
<<es-sync-rules-basic,Basic sync rules>> are identical for all connectors and are available by default.
<<es-sync-rules-advanced,Advanced rules>> for MySQL can be used to pass arbitrary SQL statements to a MySQL instance.
[IMPORTANT]
====
You need to specify the tables used in your custom query in the "tables" field.
====
For example:
[source,js]
----
[
{
"tables": ["table1", "table2"],
"query": "SELECT ... FROM ..."
}
]
----
// NOTCONSOLE
[WARNING]
====
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.
====
[discrete#es-connectors-mysql-troubleshooting]
===== Troubleshooting
See <<es-connectors-troubleshooting>>.
[discrete#es-connectors-mysql-security]
===== Security
See <<es-connectors-security>>.
// Closing the collapsible section
===============
// //////// //// //// //// //// //// //// ////////
// //////// CONNECTOR CLIENT REFERENCE ///////
// //////// //// //// //// //// //// //// ////////
[discrete#es-connectors-mysql-connector-client-reference]
==== *Self-managed connector*
.View *self-managed connector* reference
[%collapsible]
===============
[discrete#es-connectors-mysql-client-prerequisites]
===== 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 <<es-native-connectors,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 <<es-build-connector,self-managed connector requirements>>.
This connector has no additional prerequisites beyond the shared requirements, linked above.
[discrete#es-connectors-mysql-create-connector-client]
===== Create a {service-name} connector
include::_connectors-create-client.asciidoc[]
[discrete#es-connectors-mysql-client-usage]
===== Usage
To use this connector as a *managed connector*, use the *Connector* workflow.
See <<es-native-connectors>>.
To use this connector as a *self-managed connector*, see <<es-build-connector>>.
For additional operations, see <<es-connectors-usage>>.
[discrete#es-connectors-mysql-client-compatibility]
===== 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.
[discrete#es-connectors-mysql-client-configuration]
===== 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
[%collapsible]
====
```
-----BEGIN CERTIFICATE-----
MIID+jCCAuKgAwIBAgIGAJJMzlxLMA0GCSqGSIb3DQEBCwUAMHoxCzAJBgNVBAYT
AlVTMQwwCgYDVQQKEwNJQk0xFjAUBgNVBAsTDURlZmF1bHROb2RlMDExFjAUBgNV
BAsTDURlZmF1bHRDZWxsMDExGTAXBgNVBAsTEFJvb3QgQ2VydGlmaWNhdGUxEjAQ
BgNVBAMTCWxvY2FsaG9zdDAeFw0yMTEyMTQyMjA3MTZaFw0yMjEyMTQyMjA3MTZa
MF8xCzAJBgNVBAYTAlVTMQwwCgYDVQQKEwNJQk0xFjAUBgNVBAsTDURlZmF1bHRO
b2RlMDExFjAUBgNVBAsTDURlZmF1bHRDZWxsMDExEjAQBgNVBAMTCWxvY2FsaG9z
dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMv5HCsJZIpI5zCy+jXV
z6lmzNc9UcVSEEHn86h6zT6pxuY90TYeAhlZ9hZ+SCKn4OQ4GoDRZhLPTkYDt+wW
CV3NTIy9uCGUSJ6xjCKoxClJmgSQdg5m4HzwfY4ofoEZ5iZQ0Zmt62jGRWc0zuxj
hegnM+eO2reBJYu6Ypa9RPJdYJsmn1RNnC74IDY8Y95qn+WZj//UALCpYfX41hko
i7TWD9GKQO8SBmAxhjCDifOxVBokoxYrNdzESl0LXvnzEadeZTd9BfUtTaBHhx6t
njqqCPrbTY+3jAbZFd4RiERPnhLVKMytw5ot506BhPrUtpr2lusbN5svNXjuLeea
MMUCAwEAAaOBoDCBnTATBgNVHSMEDDAKgAhOatpLwvJFqjAdBgNVHSUEFjAUBggr
BgEFBQcDAQYIKwYBBQUHAwIwVAYDVR0RBE0wS4E+UHJvZmlsZVVVSUQ6QXBwU3J2
MDEtQkFTRS05MDkzMzJjMC1iNmFiLTQ2OTMtYWI5NC01Mjc1ZDI1MmFmNDiCCWxv
Y2FsaG9zdDARBgNVHQ4ECgQITzqhA5sO8O4wDQYJKoZIhvcNAQELBQADggEBAKR0
gY/BM69S6BDyWp5dxcpmZ9FS783FBbdUXjVtTkQno+oYURDrhCdsfTLYtqUlP4J4
CHoskP+MwJjRIoKhPVQMv14Q4VC2J9coYXnePhFjE+6MaZbTjq9WaekGrpKkMaQA
iQt5b67jo7y63CZKIo9yBvs7sxODQzDn3wZwyux2vPegXSaTHR/rop/s/mPk3YTS
hQprs/IVtPoWU4/TsDN3gIlrAYGbcs29CAt5q9MfzkMmKsuDkTZD0ry42VjxjAmk
xw23l/k8RoD1wRWaDVbgpjwSzt+kl+vJE/ip2w3h69eEZ9wbo6scRO5lCO2JM4Pr
7RhLQyWn2u00L7/9Omw=
-----END CERTIFICATE-----
```
====
[discrete#es-connectors-mysql-client-known-issues]
===== 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.
+
[source,console]
----
POST /.elastic-connectors/_update/connector_id
{
"doc" : {
"configuration": {
"tables": {
"type": "list",
"value": "*"
},
"ssl_enabled": {
"type": "bool",
"value": false
},
"ssl_ca": {
"type": "str",
"value": ""
},
"fetch_size": {
"type": "int",
"value": 50
},
"retry_count": {
"type": "int",
"value": 3
}
}
}
}
----
// TEST[skip:TODO]
+
* *Upgrading to 8.8 does not migrate MySQL sync rules.*
+
After upgrading, you must re-create your sync rules.
See <<es-connectors-known-issues>> for any issues affecting all connectors.
[discrete#es-connectors-mysql-client-syncs]
===== Documents and syncs
The following describes the default syncing behavior for this connector.
Use <<es-sync-rules,sync rules>> and {ref}/ingest-pipeline-search.html[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 {ref}/dynamic-mapping.html[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.
[discrete#es-connectors-mysql-client-docker]
===== Deployment using Docker
include::_connectors-docker-instructions.asciidoc[]
[discrete#es-connectors-mysql-client-sync-rules]
===== Sync rules
The following sections describe <<es-sync-rules>> for this connector.
<<es-sync-rules-basic,Basic sync rules>> are identical for all connectors and are available by default.
<<es-sync-rules-advanced,Advanced rules>> for MySQL can be used to pass arbitrary SQL statements to a MySQL instance.
[IMPORTANT]
====
You need to specify the tables used in your custom query in the "tables" field.
====
For example:
[source,js]
----
[
{
"tables": ["table1", "table2"],
"query": "SELECT ... FROM ..."
}
]
----
// NOTCONSOLE
[WARNING]
====
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.
====
[discrete#es-connectors-mysql-client-troubleshooting]
===== Troubleshooting
See <<es-connectors-troubleshooting>>.
[discrete#es-connectors-mysql-client-security]
===== Security
See <<es-connectors-security>>.
// Closing the collapsible section
===============