
I've been scrobbling my listening history to Last.fm for almost two decades now. I had a pro subscription for some time to support the site, but lack of features and active development led to it lapsing. Recently, I was pretty bummed to see that even API access will be gated behind the pro subscription. This makes sense from one perspective to increase the value of the subscription, but because I have always relied on open access to the API as a means of getting my data out of Last.fm. This no longer is possible, and I don't really feel the desire to develop apps on the platform now that it's no longer as open. All this is to say I was extra motivated to get my scrobbles out of the site and into a local MariaDB table that I could play with at my leisure.
The first step is to export your scrobbles. The first export was massive in my case since my history goes back to 2007. The upshot is after loading the first huge export, subsequent ones will be much smaller. Since the API access change has gone into effect, some Last.fm export apps in the wild won't work... because the developer isn't Pro. This isn't always the case-- there is a pretty strong overlap between fans of Last.fm and people who want to build apps on its API.
One such export site is https://lastfm.ghan.nl/export/.
After you've got your scrobbles, and assuming you already have a MySQL or MariaDB database up and running, the following will create a scrobbles table with the correct schema. Based on the schema, we need at least track and artist, but all Musicbrainz ids and album can be NULL.