For most of my career, I’ve learned just enough SQL to get by. With all the lovely libraries and cozy query builders around, it’s really not too hard for a programmer (at least this programmer that is) to get along fine without … well, without actually knowing SQL (did I just admit this in writing?!).
Part of the problem is my learning isn’t regular enough to remain sticky. In an effort to fight that, I’ve decided to be more deliberate about doing a little bit of SQL each day.
A useful resource for this (and one used in O’Reilly’s excellent Learning SQL book) is a fully-seeded sample database provided by MySQL called Sakila . Showing its age, it’s a database chalk-full of data relating to a video rental store. Nonetheless, it’s fun to have a set of interconnected tables to play with.
But of course, in true programmer fashion, it wasn’t enough to just get a MySQL database running locally — no of course not — I had to do it in Docker! So with a little fiddling of my own and some help from an open source library I wrote a little Dockerfile to build an image that had everything I needed.
After unzipping the data from the download
into the root of a directory, I also created a Dockerfile
in the root.
The contents of which were —
Without going into too much detail, I basically install mysql
, allow an empty password, import the sakila database, and then tell the image when run to start up the mysql server.
To get everything running, I then had to run
And then I was in the mysql
prompt! Running show tables;
showed the sakila database tables and I knew I was in business.
Now you can exit the mysql prompt and as long as you keep the sakila
container running, you should be able to run that last docker exec
command and access the tables with any modifications you make. You can find all of this code and these instructions on my Github Repo
as well.
Alright, this is it! 2023 is going to be my year for SQL. That is, unless ChatGPT learns it for me first 😅