r/Database • u/alishahimtiaz • Jan 07 '20
How do I create a database from scratch (something similar to mysql)
Hello.
I'm currently a junior in university and I have been messing around with SQL for years. I'm familiar with SQL and noSQL DB's, and the next step I want to take is to create a database from scratch (and make the query language etc). The latter should be done with grammars/compilers which wouldn't be too difficult. How do I actually make the database part itself? I' probably will have to use Rust / C++, don't think I can do transactions in Python, but I would like to do it in Python if possible.
Any resources you guys would recommend / research papers to read? Trying to do it as a side project for fun.
Thanks.
8
1
u/boy_named_su Jan 07 '20
https://en.m.wikipedia.org/wiki/Advanced_Programming_in_the_Unix_Environment has several chapters walking you through building a simple rdbms from scratch in C
I'd also check out SQLite's source code
1
2
u/DataDecay Jan 07 '20
I can second this, the src of sqlite is very well done, very well organized, and at a mid-size level as opposed to some non embedded client server DBMSs.
3
u/petercooper Jan 07 '20
The question is a bit like "how do I build a house from scratch"? You can get lots of advice and guidance, but ultimately there are a million ways to do it and lots of different types of design you could follow (or not).
A common approach with new databases is to find a solid key/value store (such as RocksDB) and then build your own database structures, replication, and querying language on top of it. But then.. if you're going down this route, maybe you'd like to build your own key/value store from scratch too? :-)
3
u/AQuietMan PostgreSQL Jan 07 '20
FWIW, MySql is a database management system (DBMS), not a database.
Code for open source DBMS is available online.
1
u/thancock14 Jan 07 '20
I would look at key value databases like berkeleydb or lmdb or wired tiger. They have good tooling around them and are basically a nice building block for a database. You can store a key (say an integer) and a value (say a class type serialized to binary) Then you can create indexes by creating another kv file that takes a field in that class as the key and the original file key as the value.
1
u/camerontbelt Jan 07 '20
Install sql server, then it asks you to give your server a name. Then you start adding databases to your hearts content. Pretty simple.
3
1
u/gamecrow77 Sep 09 '26
bro did you code it ?
what is the best resource , im also looking for something like this , just to write a RDBMA so i can learn fundamentals , like btree , file systems and fsyncs and some c++ also
to open up my mind
1
11
u/Tostino Jan 07 '20
Look up the database courses CMU puts up on YouTube. It's super informational and digs in deep on the internals... Don't expect it to be easy though.