<p>Several options:</p>

<ol>
<li><p>Connect to the bitcoin network directly, parse all messages, verify the blocks and insert all the transactions contained within it into the MySQL db. This is going to be a bit hard since you have to write code to connect to the network.</p></li>
<li><p>Run bitcoind side-by-side with the MySQL db and use some combination of the <code>getblockcount</code>, <code>getblockhash</code>, <code>getblock</code>, <code>gettransaction</code> RPC commands and insert the transaction data into the MySQL db. You can run a cron on this every 5 minutes or so and you should have a fairly up-to-date MySQL db. This comes at the cost of considerable disk space since you'll need to have the entire blockchain for bitcoind (30 gigs and growing).</p></li>
<li><p>Connect to some other service and get the data that way. Blockchain.info is the obvious one and they have a wonderful API for getting all the new data you need. Unfortunately, you'll have to trust them to provide the right data. There's also electrum servers which provide data using stratum and ABE and some others. Heck, if you can get someone to open up their RPC port (8333) on bitcoind, you can connect to their bitcoind and use the same commands as #2. The drawback here is that you have to trust a third party in some way, shape or form, though, of course, you can write your own verification code.</p></li>
</ol>

<p>Regardless of which thing you choose, you'll need to handle some difficult things like orphaned blocks when trying to keep this db up-to-date.</p>

CC BY-SA 3.0
2015-02-02T16:30:32.643Z
Thanks Jimmy. I will do some messing around and see what works best.
Brian Koffler
CC BY-SA 3.0
2016-08-22T22:16:21.477Z
Perhaps consider if MySQl is the best type of DB to go here with. I would root for a graph DB like Neo4j or OrientDB. It will make things easier when querying the data IMO.
Albert S
CC BY-SA 3.0
2015-02-02T16:11:02.973Z
2015-02-02T16:11:02.973Z
Jimmy Song
<p>I know there are similar posts here about utilizing MySQL as the basis for an application which contains the contents of the blockchain, but i have not seen any on-point answers to the issue of updating the database after the initial dump.</p>

<p>Assuming i move forward with blockparser or ABE (or another application which you believe works better), how do i update the database after the initial dump? I have not implemented any solution yet as i would like to have this piece figured out before diving in.</p>

<p>My goal is to have my local blockchain inserted into MySQL, and then have periodic updates occur to keep the database up to date.</p>

<blockchain><bitcoind><mysql>
Blockchain MySql Implementation - Updating Database
Brian Koffler
# Blockchain MySql Implementation - Updating Database

(Asked by: username_0 on 2015-02-02)

I know there are similar posts here about utilizing MySQL as the basis for an application which contains the contents of the blockchain, but i have not seen any on-point answers to the issue of updating the database after the initial dump.

Assuming i move forward with blockparser or ABE (or another application which you believe works better), how do i update the database after the initial dump? I have not implemented any solution yet as i would like to have this piece figured out before diving in.

My goal is to have my local blockchain inserted into MySQL, and then have periodic updates occur to keep the database up to date.

**Tags:** blockchain, bitcoind, mysql


---

## 1 answers

### Answer by username_1 on 2015-02-02. Score: 1 | Accepted answer

Several options:

1. Connect to the bitcoin network directly, parse all messages, verify the blocks and insert all the transactions contained within it into the MySQL db. This is going to be a bit hard since you have to write code to connect to the network.
2. Run bitcoind side-by-side with the MySQL db and use some combination of the `getblockcount`, `getblockhash`, `getblock`, `gettransaction` RPC commands and insert the transaction data into the MySQL db. You can run a cron on this every 5 minutes or so and you should have a fairly up-to-date MySQL db. This comes at the cost of considerable disk space since you'll need to have the entire blockchain for bitcoind (30 gigs and growing).
3. Connect to some other service and get the data that way. Blockchain.info is the obvious one and they have a wonderful API for getting all the new data you need. Unfortunately, you'll have to trust them to provide the right data. There's also electrum servers which provide data using stratum and ABE and some others. Heck, if you can get someone to open up their RPC port (8333) on bitcoind, you can connect to their bitcoind and use the same commands as #2. The drawback here is that you have to trust a third party in some way, shape or form, though, of course, you can write your own verification code.

Regardless of which thing you choose, you'll need to handle some difficult things like orphaned blocks when trying to keep this db up-to-date.

> **Comments:**
> **username_0**: Thanks username_1. I will do some messing around and see what works best.  
> **username_2**: Perhaps consider if MySQl is the best type of DB to go here with. I would root for a graph DB like Neo4j or OrientDB. It will make things easier when querying the data IMO.  

---

