You will probably want to write a script that queries an api like blockchain.info and extract the data you want to store in your database. I would imagine this being the easiest way
This won't work. You will hit query limits with them. And/or it will be slow.
Run your own node and extract the data you need using rpc.