r/Database • • 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.

53 Upvotes

23 comments sorted by

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.

2

u/alishahimtiaz Jan 07 '20 edited Jan 07 '20

Just skimmed the video titles, they look very helpful (Intro / Advanced DB's). Thank you very much!

2

u/Nietzsche94 Mar 16 '22

2

u/Tostino Mar 16 '22

That'd be the one ;)

2

u/Nietzsche94 Mar 16 '22

thanks mate, a great resource, i dont think i would've found it without your comment,

have you got any luccks building a RDBMS from scratch, do u recommend any other resource?

do u suggest any resource that tackle the data warehousing/ MPP databses the same (fundamental) way?

1

u/Tostino Mar 20 '22

Sorry, but it's just an interest that I don't actually have time to persue at this point. I just like using the extra knowledge to stay current with research and to give me better intuition when debugging issues, and to design data models that work with best with the database implementation of choice.

1

u/zhangysh1995 Jan 07 '20

The course is also very helpful with my research! It points out a road to dig deeper into the dabatase engine.

1

u/divine304 Oct 02 '23

ty for sharing this

1

u/Early-Goat-4424 Mar 03 '24

what are you up to on this ?

1

u/divine304 Aug 19 '24

No where. Did you make any progress on it?

8

u/wolf2600 Jan 07 '20

Trying to do it as a side project for fun.

HA!

1

u/dalton_zk May 30 '24

I think the same!

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

u/alishahimtiaz Jan 07 '20

Thank you, I'll check out the book and SQLite source code!

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

u/therealPaulPlay Jul 02 '25

The question is about developing your own.

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

u/shamnad_sherief Sep 23 '26

Any update on this? OP?