Setup Solr 6.x with MySQL



This article is a step by step tutorial on how to get Solr 6.x configured with MySQL and run your first data import.

Download Solr and create your first collection

1. Download latest 6.x Solr release from
2. Open the folder and start Solr instance and create your first core

./bin/solr start
./bin/solr create -c collection1

3. Open http://localhost:8983/solr/ and check that collection has been created.

Edit solrconfig.xml

4. Go to ./server/solr/collection1/conf/solrconfig.xml and edit solrconfig.xml, add the following before existing <lib… statements:

<lib dir="${solr.install.dir:../../../..}/contrib/dataimporthandler/lib" regex=".*\.jar" />
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-.*\.jar" />

And the following to section <!– Request Handlers

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">solr-data-config.xml</str>

Save and close the file.

Create solr-data-config file

5. Create a file called ./server/solr/collection1/conf/solr-data-config.xml with the following contents

<dataSource type="JdbcDataSource"
<entity name="entity_name"
<field column="id" name="id"/>
<field column="name" name="name"/>

Make sure you replace username and password, and corresponding query for the entity. Describe each field as needed.

Connect with Mysql and restart Solr

6. You will need to add the following. Download JDBC driver for MySQL from

Copy file from the downloaded archive ‘mysql-connector-java-*.jar’ to the folder ‘./contrib/dataimporthandler/lib’ in the folder where Solr was installed. Create ‘lib’ folder if needed.

7. Restart Solr

./bin/solr restart

8. Go to http://localhost:8983/solr/, find your collection and add your fields as needed to the schema (select Schema in collection menu).

9. Do a full import by selecting Dataimport from the menu, execute it.

You should now have a working Solr instance. If your query is empty, and no documents indexed, please inspect Logging section, it should give you some hints about what is happening.

Leave a comment


  1. Vineel says:

    This got me started, fast! Works just fine on Solr 7.2.1 too.

  2. sikanth says:


    do you have any article on elastic search setup in Windows Home edition?

  3. MGrant says:

    Wow! Finally, a tutorial that works! I have seen a LOT of SOLR tutorials and none of them worked the first time, like yours did…! Thank you for this simple, but extremely useful tutorial!