MySQL Blog Archive
For the latest blogs go to blogs.oracle.com/mysql
Give me a MySQL and Make it Snappy!

MySQL is available for a huge variety of platforms, in a wide range of packaging formats and through many channels. Part of our mission is to keep up with the times by making sure that all MySQL products are available where people expect and need them to be. As part of that we have invested a lot of work in modernizing our Linux packaging and distribution, improving our story on Windows and introducing strong support for new and exciting deployment formats such as Docker.

Snaps and MySQL

We’re now taking another step in this area by publishing our first iteration of snap packaging for MySQL Server. At its very core, an application packaged as a snap is a zip file of the application itself, augmented with its runtime dependencies (e.g. third party libraries) and a fairly simple description of security requirements and the ways that the application interfaces with the rest of the system. The result is a generic package that will instantly deploy and run on virtually any kind of Linux system. The application will be running securely inside its own sandbox, isolated from other applications as well as the underlying system. Conceptually and technically this is closely related to full blown containerization in e.g. Docker.

Build it yourself

Snaps are usually hosted in online repos called “stores”, see below for how to get quickly up and running with an experimental MySQL from the Ubuntu Snap Store. Additionally, the necessary code to build a simple snap for MySQL Server is available on Github. Before you proceed, though, do note that these snaps are very experimental. The setup is only very lightly tested and it has issues and limitations that make them guaranteed to be unsuitable for any use beyond simple prototyping. More on that towards the end of this posting.

Check out our Snap git repo (5.7 or 8.0 branch), e.g for 5.7:

git clone -b 5.7 https://github.com/mysql/mysql-snap

Then run snapcraft in the top level directory of your git checkout:

cd mysql-snap
snapcraft

This gives you a shiny, new mysql_<version>_amd64.snap.

To install it, simply do:

sudo snap install --dangerous mysql_<version>_amd64.snap

(Don’t worry too much about the --dangerous in our scenario: the snap we produced wasn’t signed, and the snap tool needs to be told to disregard that.)

… Or Install from the Ubuntu Snap Store

Alternatively, you can install from the Ubuntu Snap Store, where we are posting our experimental snaps:

snap install --channel=<keyword> mysql

Use the keyword beta for MySQL 5.7 and edge for the 8.0.0 pre-GA milestone release. Do note that things will very likely change around in the future, but this is the channel mapping we’re using right now.

Run it

Finally, start up MySQL:

sudo snap connect mysql:process-control core:process-control
mysql.startup

Please note the MySQL admin password output by the startup command. That command also carries a caveat: you currently can’t start MySQL from a snap as the system user root. Generally, the usual way of running MySQL is to start it as root, then it will automatically drop privileges by switching to a dedicated user that has the exact necessary set of file and directory permissions. The problem is that switching users and changing file ownership and permissions isn’t currently supported for a service running from inside a snap. You can work around this by installing the snap with the --devmode option, but be warned that this disables most of Snappy’s security restrictions and thus nullifies some of the key advantages of using snaps in the first place. We are discussing this issue with the Snap guys over at Canonical and expect it to get resolved in the future.

Anyway, you should now have an initialized and running MySQL Server instance, to which you can connect by running mysql.client -uroot -p, inputting the password given by the mysql.startup command.

Those were the basics, and you can find a good deal more information about the MySQL snaps over on Github.

Going Forward

As we briefly touched on above there are some limitations in this very first iteration of the MySQL snaps, some of them just because this is a first iteration, some caused by issues in MySQL itself, and some of them due to current limitations in the Snap system itself:

  • MySQL requires process-control permissions to run. That is why you need to do the somewhat alien looking sudo snap connect mysql:process-control core:process-control after installing the snap, setting these permissions manually. That also means that it is not currently possible to have the server automatically start up after installation. This appears to be an issue in MySQL itself, and we are looking into it.
  • We need the Snap system to support some operations that require root permissions. Once that is in place, we can make our snaps behave properly when run as root.
  • We currently have no upgrade support in these snaps.
  • Removing a snap removes the database. This is akin to what you get if you run MySQL in a Docker container and naïvely put your database in the same container. This will obviously need to be addressed at some point.
  • We’d like to support parallel installation of multiple versions of MySQL using snaps. Time will show whether we do that directly in our snaps or whether Snap itself gets features to seamlessly handle parallel versions in the future.

All in all, Snap shows promise, and it could very well become a great future vehicle for the MySQL family of products.

Hopefully, you appreciated this little glimpse into what we spend time on when we’re not cranking the big machinery that churns out the huge and continuous stream of MySQL releases, and perhaps we also inspired you to get your hand dirty with the snap system. Try it out and let us know what you think in the comments section below.