I understand that the data in a blockchain is stored in a database. E.g., this post states that Ethereum uses LevelDb or RocksDb. I expect that normally the only access to this database is through smart contracts, but is there anything preventing someone from modifying the underlying database out of band e.g., using the APIs that come with the database? What would happen in that case? Wouldn't the changes propagate to other copies of the database? And wouldn't that amount to a hack? How is the blockchain secured from such hacks?
What would happen in that case?
Your copy would be invalid. You might be able to fool yourself with some odd responses from your node, but the network is indifferent to malfunctioning nodes. Nothing you do would alter the history agreed on by the rest of the network.
Wouldn't the changes propagate to other copies of the database?
No. Properly functional nodes would ignore invalid blocks emitting from your node.
And wouldn't that amount to a hack?
Blockchain is a data structure with a kind of in-built integrity that would be broken by your out-of-band edit. You wouldn't be able to make it work.
How is the blockchain secured from such hacks?
The entire network agrees on the history of everything that happened and strict rules about what can happen. Your out-of-band edit would be recognized as unacceptable. It might help to consider that far from a typical cluster, blockchain nodes do not necessarily trust each other and up to 49% can be deliberately hostile to the network - the network will not budge.
Perhaps others will chime in with more technical resources to explain how that works.
Hope it helps.
You can modify your database, so that for example, you have more coins than everyone else.
However, everyone with the blockchain knows that isn't true, so will ignore whatever transactions you have of spending coins that you do not have.
Having the blockchain means running consensus software: software that everyone has agreed to run. This software checks what is valid and what is not, and will prevent your hacked changes from affecting the blockchain.