Skip to main content
Use the MySQL connector to index from a MySQL table without writing an indexing script. In this quickstart, you import a sample product dataset into MySQL, create a source for this database table, use an Algolia destination, and create an on-demand synchronization task.

Before you begin

Make sure you have:
  • An Algolia account. Create one for free if you don’t already have one.
  • A MySQL host that Algolia can reach. Use a hosted MySQL server or configure an SSH tunnel to your server. Algolia can’t connect directly to a database that’s only accessible through 127.0.0.1 or localhost on your machine. To use an SSH tunnel, make sure the SSH host can reach the database.
  • Your MySQL host’s port number. The default is 3306 but your provider may use a different port.
  • A MySQL database. Create or choose a database for the sample data and note its name. For more information, see Creating and selecting a database.
  • A MySQL username and password. To import the sample data, the user needs CREATE, DROP, INSERT, and SELECT access to the target database. For more information, see GRANT Statement.

Set up the MySQL connector

Create a source, destination, transformation, and synchronization task for the sample product dataset.
  • The source tells the connector which MySQL database to read.
  • The destination tells the connector which Algolia index to write to.
  • The transformation adds a price_range attribute to the records.
  • The task controls which table to index and when the connector runs.
1

Download the sample SQL file

2

Import the sample data into MySQL

This script replaces any existing apparel table in your database.
Run the script:
Replace MYSQL_HOST, MYSQL_PORT, MYSQL_USER and MYSQL_DATABASE with your MySQL connection details.When prompted, enter the password for MYSQL_USER.For more information, see Executing SQL statements from a text file.
3

Verify the import

Run:
When prompted, enter the password for MYSQL_USER.The SQL query should return 1000 records.
4

Choose the MySQL connector

Go to the Algolia dashboard and select your Algolia application. Open the Connectors page.Find MySQL, then select Connect.
5

Configure the MySQL source

Under Configure your data source, select Create a new source.Enter the connection details for the database table that contains the sample data:Under SSH Tunnel Method, select No Tunnel if Algolia can connect directly to your database. Otherwise, configure the authentication for your SSH tunnel.
6

Create the MySQL source

In Connector name, enter Quickstart products MySQL source, then select Create source.
7

Transform the records

This transformation adds a price_range attribute to each record. After the connector indexes your records, you can display price_range or configure it as a facet.Select Transform using the code editor and replace the placeholder Transformation code with this function:
JavaScript
Select Save.
8

Choose the destination index

Under Configure your destination, select Create a new destination.Under Search, enter quickstart-products as the index name.
If you enter the name of an existing index, the connector overwrites the records and settings in that index.
9

Create the destination

Under Index credentials, select Create one for me.To use an existing API key, choose one with the addObject, deleteIndex, and editSettings ACLs.In Name, enter MySQL quickstart products destination, then select Create destination.
10

Create and run an on-demand synchronization task

Under Configure your task, select On demand.Select the apparel table and keep all its columns selected. Confirm that the connector maps the table’s objectID primary key to each record’s Algolia objectID.Select Create task, then Run and wait for the task to finish.
11

Verify the indexed records

When the task completes, open the quickstart-products index in the Algolia dashboard. Check that the index contains 1,000 product records with attributes such as title, description, product_type, price, price_range, and showcase_image.
You can use this index as the data source for Build your first search experience.Before you build the UI, configure product_type as an attribute for faceting in the quickstart-products index.

Index your own MySQL data

Use a dedicated read-only MySQL account with access only to the tables you want to index, and restrict network access to Algolia’s connector IP addresses.

Set up a dedicated MySQL connector user

Connect to MySQL with an account that can create users and grant privileges. Run the following statements in the MySQL client or your hosting provider’s SQL console. Create a dedicated connector user and grant it SELECT access to the table you want to index. For example:
SQL
Replace MYSQL_USER_PASSWORD and MYSQL_DATABASE.TABLE_NAME with your connector user’s password, database, and table name. If the user already exists, run only the GRANT statement.

Allow the Algolia connector to reach your MySQL server

The % host permits remote connections.
For production databases, restrict inbound connections to Algolia’s connector IP addresses or use an SSH tunnel.

Allow Algolia IP addresses

If your source restricts access by IP address, allow these Algolia IP addresses:
  • 104.196.103.173
  • 35.234.69.129

Configure the connector for your data

  1. Follow the steps to configure the MySQL source and create a synchronization task: replace the sample connection details and apparel table with your own database details and tables.
  2. Use the dedicated connector user you created.
  3. Review the transformation and destination index to make sure they’re appropriate for your data.

Secure the connection

Configure connection security (SSL modes) in your MySQL source. SSL modes control whether the connector encrypts the connection to your MySQL server and verifies the server’s identity. An SSH tunnel lets the connector reach a database that isn’t directly accessible from Algolia. Depending on your setup, you can use SSL, an SSH tunnel, or both.

Configure SSL

Choose an SSL mode that matches your MySQL server’s TLS configuration:
  • Preferred. The connector uses SSL if the MySQL server supports it. Otherwise, it connects without SSL.
  • Required requires an encrypted connection but doesn’t verify the server certificate.
  • Verify CA requires encryption and verifies the server certificate against a trusted certificate authority. Add the CA certificate supplied by your database provider to CA certificate.
  • Verify Identity requires encryption, verifies the server certificate against a trusted certificate authority, and checks that the certificate matches the host name. Add the provider’s CA certificate.
Leave Client certificate and Client key empty unless your MySQL server requires mutual TLS authentication. If it does, add the client certificate supplied by your database provider to Client certificate and its corresponding private key to Client key.

Connect through an SSH tunnel

If Algolia can’t connect directly to your MySQL database, connect through an SSH host. Select an authentication method:
To authenticate with an RSA private key:
  1. Generate an RSA key pair in PEM format:
  2. Add algolia_mysql_rsa.pub to the SSH user’s authorized keys on the bastion host.
  3. In the MySQL source configuration, select SSH Key Authentication under SSH Tunnel Method.
  4. Enter the SSH Tunnel Jump Server Host, SSH port, and SSH Login Username.
  5. Add the contents of algolia_mysql_rsa to SSH Private Key.

MySQL data types

The connector maps MySQL values to JSON-compatible Algolia attributes. In particular:
  • DECIMAL values become numbers.
  • TINYINT(1) values become booleans by default.
  • Native MySQL JSON values become serialized JSON strings.
  • TEXT and LONGTEXT columns remain strings, including columns that contain JSON-encoded data.
For JSON-encoded strings, use a transformation to convert them into arrays or objects before indexing.

Transformations

Use transformations to add computed attributes or change values before the connector indexes your records. To use a transformed attribute for search, faceting, or ranking, update the relevant index settings, such as searchableAttributes, attributesForFaceting, or customRanking.
Test transformations with repeated task runs. Transformations that read from and write to the same attribute, or extract a value and then delete the source attribute, can produce different results when the task runs again.

Synchronization schedule

After you create a task, you can edit it in the Algolia dashboard to choose when the connector runs:
  • On demand. Run the connector manually.
  • Scheduled. Select a predefined schedule or enter a custom cron expression.
Schedules use UTC. For interval schedules, such as 0 */4 * * * and all predefined schedules, such as Every day, Algolia offsets each task’s scheduled run time by a fixed amount to distribute task executions over time. A task uses the same offset for every run. The offset is always shorter than the interval between runs. For example, 0 */4 * * * schedules a task every four hours, starting at 00:00 UTC. With an offset of 2 hours and 37 minutes, the task would instead run at 02:37, 06:37, and 10:37 UTC. To schedule a task at specific times, list the hours in the cron expression. For example, 0 0,4,8,12,16,20 * * * schedules a task at 00:00, 04:00, 08:00, 12:00, 16:00, and 20:00 UTC.

Indexing strategy

You can choose how the connector updates your index. For information about full reindexing, full record updates, and partial record updates, see Data synchronization strategies.

Limitations

This connector is subject to the following limitations:

See also

Last modified on November 26, 2026