skip to Main Content

I am trying to index a mysql database on phpmyadmin into solr.

SOLVED BY @MatsLindh

I have tried to find information necessary but no tutorials I have found deal with this setup.

MY DATABASE:
My mysql db is locally hosted and accessed through phpmyadmin. Here is the admin page.
phpmyadmin admin ui

As you can see I have a db titled solrtest with table solr having fields id, date, Problem, and Solution.

Now to link my db, the tutorials online were a bit inconsistent. The most consistent parts told me I would need to use solrs DataImportHandler and the mysql-connector-java. Another also mentioned a jdbc plug in. I have installed and put the .jar files here in my solr/dist directory.solr dist file
In some tutorials they have these also in the contrib folder but I have left in /dist.

MY FILES:
I have created a core titled solrhelp and made the following changes in the solhelp/conf files.

solrconfig.xml

<lib dir="C:Program FilesSolrsolr-7.5.0dist" regex="solr-dataimporthandler-7.5.0.jar" />
  <lib dir="C:Program FilesSolrsolr-7.5.0dist" regex="solr-dataimporthandler-extras-7.5.0.jar" />
  <lib dir="C:Program FilesSolrsolr-7.5.0dist" regex="mysql-connector-java-8.0.13.jar" />
  <lib dir="C:Program FilesSolrsolr-7.5.0dist" regex="sqljdbc41.jar" />
  <lib dir="C:Program FilesSolrsolr-7.5.0dist" regex="sqljdbc42.jar" />
  <requestHandler name=" /dataimport" class=" org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name=" defaults">
    <str name=" config">data-config.xml</str>
    </lst>
  </requestHandler>
  <requestHandler name " /dataimport" class=org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
      <str name="name">solrhelp</str>
      <str name="driver">jdbc:mysql.jdbc.Driver</str>
      <str name="url">jdbc:mysql://localhost:8983/solrtest</str>
      <str name="user">root</str>
      <str name="password"></str>
    </lst>
  </requestHandler>

the created data-config.xml

<dataConfig>
<dataSource type="JdbcDataSource"
            driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:8983/solrtest"
            user="root"
            password=""/>
    <document>
    <entity name="solr"
            pk="id"
            query="select id, date, Problem, Solution from solr"
        >
        <field column="id" name="id"/>
        <field column="date" name="date"/>
        <field column="Problem" name="Problem"/>
        <field column="Solution" name="Solution"/>
    </entity>
    </document>
</dataConfig>

and the managed-schema.xml

 <field name="id" type="string" indexed="true" stored="true" multiValued="false" />
  <field name="pdate" type="date" indexed="true" stored="true" multiValued="false" />
  <field name="Problem" type="text_general" indexed="true" stored="true" />
  <field name="Solution" type="text_general" indexed="true" stored="true" />

My question to the community is rather broad and I apologize. I want to know what all I am missing before I attempt to post this db. I dont think I have edited my files correctly and I dont really know of a way to test them before I attempt to post.
It should be noted that in the dist folder I have two verions of the jdbc and have both in my solrconfig.xml file.
Any direction to better tutorials or documentation would be appreciated.

UPDATED FILES
solrconfig

  <lib dir="C:Program FilesSolrsolr-7.5.0dist"
    regex="solr-dataimporthandler-7.5.0.jar" />
  <lib dir="C:Program FilesSolrsolr-7.5.0dist"
    regex="solr-dataimporthandler-extras-7.5.0.jar" />
  <lib dir="C:Program FilesSolrsolr-7.5.0contribdataimporthandlerlib"
    regex="mysql-connector-java-8.0.13.jar" />
  <lib dir="C:Program FilesSolrsolr-7.5.0contribdataimporthandlerlib"
    regex="sqljdbc41.jar" />
  <lib dir="C:Program FilesSolrsolr-7.5.0contribdataimporthandlerlib"
    regex="sqljdbc42.jar" />

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

data-config

<dataConfig>
<dataSource type="JdbcDataSource"
            driver="com.mysql.cj.jdbc.Driver"
            url="jdbc:mysql://localhost:8983/solrtest/solr"
            user="root"
            password=""/>
    <document>
    <entity name="solr"
            pk="id"
            query="select * from solr"
        >
        <field column="id" name="id"/>
        <field column="date" name="date"/>
        <field column="Problem" name="Problem"/>
        <field column="Solution" name="Solution"/>
    </entity>
    </document>
</dataConfig>

2

Answers


  1. Chosen as BEST ANSWER

    THIS PROBLEM WAS SOLVED BY @MatsLindh

    My issue was configuration syntax. Below are the corrected data-config.xml and solrconfig.xml

    data-config

    <dataConfig>
    <dataSource type="JdbcDataSource"
                driver="com.mysql.cj.jdbc.Driver"
                url="jdbc:mysql://localhost:3306/solrtest"
                user="root"
                password=""/>
        <document>
        <entity name="solr"
                pk="id"
                query="select * from solr"
            >
            <field column="id" name="id"/>
            <field column="date" name="date"/>
            <field column="Problem" name="Problem"/>
            <field column="Solution" name="Solution"/>
        </entity>
        </document>
    </dataConfig>
    

    solrconfig

    <lib dir="C:Program FilesSolrsolr-7.5.0dist"
        regex="solr-dataimporthandler-7.5.0.jar" />
      <lib dir="C:Program FilesSolrsolr-7.5.0dist"
        regex="solr-dataimporthandler-extras-7.5.0.jar" />
      <lib dir="C:Program FilesSolrsolr-7.5.0contribdataimporthandlerlib"
        regex="mysql-connector-java-8.0.13.jar" />
      <lib dir="C:Program FilesSolrsolr-7.5.0contribdataimporthandlerlib"
        regex="sqljdbc41.jar" />
      <lib dir="C:Program FilesSolrsolr-7.5.0contribdataimporthandlerlib"
        regex="sqljdbc42.jar" />
    
      <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
        <lst name="defaults">
        <str name="config">data-config.xml</str>
        </lst>
      </requestHandler>
    

  2. You don’t import “through phpmyadmin”. You use the connection information to your MySQL server. There is no http involved. jdbc:mysql://localhost:3306/dbname would be the string in your case, assuming that MySQL runs on the same computer as you’re running Solr on.

    Pay close attention to the port number (3306) in the connection string and the dbname. It should refer to the values of your MySQL server and not your Solr server.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search