Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter Twenty. Database Sharding Distributor > Configure the Sharding Driver

Configure the Sharding Driver

As we mentioned earlier, the sharding JDBC driver has its own configuration file, shard-config.xml:

<dbshards-config>

  <database
    name="hello" db-platform="MySQL"
    db-version="5.1" driver="com.mysql.jdbc.Driver">

    <table name="person">
      <column name="id" type="int" key="true"/>
      <column name="first_name" type="varchar(50)" />
      <column name="last_name" type="varchar(50)" />
      <shard-strategy type="range" key="last_name">
        <vshard id="1" start="A" end="E" />
        <vshard id="2" start="F" end="M" />
        <vshard id="3" start="N" end="S" />
        <vshard id="4" start="T" end="Z" />
      </shard-strategy>
    </table>

  </database>

  <!-- Mapping of virtual shards to physical shards -->
  <shard-mapping>
    <shard id="1"
      jdbc-url="jdbc:mysql://server1/shard1"
      user="user" password="password" vshards="1"  />
    <shard id="2"
      jdbc-url="jdbc:mysql://server2/shard2"
      user="user" password="password" vshards="2"  />
    <shard id="3"
      jdbc-url="jdbc:mysql://server3/shard3"
      user="user" password="password" vshards="3"  />
    <shard id="4"
      jdbc-url="jdbc:mysql://server4/shard4"
      user="user" password="password" vshards="4"  />
  </shard-mapping>

</dbshards-config>

					  



  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial