Take the new MySQL Shell for a Spin … in Docker!

The most recent release of MySQL Server — 5.7.12 — ships with the X Plugin, which opens up an entirely new area of functionality: In addition to the classical relational approach to data management using SQL, MySQL can now also be used as a schemaless document store, something which is commonly referred to as a NoSQL database.

In order to support document store operations, we ship a new shell, currently in alpha, that introduces functions to query, update and manage MySQL as a document store, using popular scripting languages such as JavaScript and Python. It also covers the same areas of usage as the venerable mysql command line client, so you can also use it to perform classical, relational SQL operations on your database.

Get Going

With the shell currently in alpha, it is a bit early to base your production database management on it, but using Docker we have set up a very easy way for you to take it for a spin and get an idea not only of the capabilities of the shell itself, but also of the versatility and flexibility of the new document store. We won’t even assume that you have a MySQL Server instance around to play with. Here is how to do it:

Spin up a MySQL Server container. The following gives you a container named mysql-container, running the latest version of MySQL Server. Substitute the root user password you want, but please note that this is not a secure way to run MySQL in Docker and should not be used on production systems.

docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=my-password -d mysql/mysql-server:latest

Start a MySQL Shell container and enable the X Plugin. Before you can start using MySQL as a document store, you will need to enable the server side plugin that provides this functionality. The following command line will start a Shell container, initiate a shell session against the MySQL server, enable the plugin, then stop and delete the shell container:

docker run -it --link mysql-container --rm -e MYSQL_HOST=mysql-container mysql/shell init

Spin up the shell and try it out! Finally, we start a normal shell user session against the MySQL container. Substitute the name of the user as appropriate; if you follow this guide to the letter, you should log in as root using the password you set on the command line when spinning up the MySQL server:

docker run -it --link mysql-container mysql/shell -u username -h mysql-container

More information on the MySQL Shell Docker image is available over on Docker Hub, including how to use it against a non-containerized MySQL instance, which is just a simple variation on the steps above.

Some Things to Try Out

Now that you have a MySQL Shell container up and running, one thing you might want to do is check out the tutorials in the MySQL 5.7 Reference Manual. There is one on using it with JavaScript and one for Python. And there is the MySQL Shell User’s Guide which provides in-depth information on the functionality currently available in the new MySQL Shell.

There is also a series of posts over on the MySQL Server Team Blog that you may want to look at. In particular these ones:

With that, here’s hoping that I have whetted your appetite a bit to go see what this new stuff is all about, and I hope we have given you an easy and straightforward way to do so. If you encounter issues or have suggestions for improvements or just want to comment, please either drop us a line here or file a bug in the MySQL bug database.

Yngve Svendsen

About Yngve Svendsen

Yngve Svendsen has been part of the MySQL organization since 2008. Based in Trondheim, Norway, he is Senior Director of MySQL Engineering Services and responsible for Release Engineering, QA and development lab IT services for the MySQL org at Oracle. Back in the mists of time he majored in mathematics before the dot com wave swept him into the devops field, first at the database startup company Clustra Inc. and then for Sun Microsystems. In 2005 he joined the Dark Side by becoming a manager in Sun's Database Group which was merged into the MySQL org when Sun acquired MySQL in 2008.

3 thoughts on “Take the new MySQL Shell for a Spin … in Docker!

  1. Thanks for the tips. I have two quick comments (to which I will expand later in an article on this topic):

    1. Using a separate Docker image for the shell is a waste. It requires 296 MB for the server and 239 MB for the shell. I understand that the shell is still an alpha product (https://bugs.mysql.com/bug.php?id=81186) but still having a copy in the container would not hurt anyone.

    2. Running the shell twice, as explained in your instructions, results in a ghost container being generated, which then require cleanup. The plugin can also be enabled with an SQL command from the server. A better way would be the following:

    docker run –name mysql-container \
    -e MYSQL_ROOT_PASSWORD=my-password \
    -d mysql/mysql-server:latest \

    1. Hi, Giuseppe, and thanks for your comments.

      I understand your points about the shell not necessarily needing a separate container, although the additional space used isn’t quite as dramatic as the number you quote (the containers share the basic OS layer). Not sure we’ll change our decision not to mix alpha status bits into a server image that is meant to be production quality, though.

      As regards the first shell container hanging around, thanks for uncovering an error in the blog text: I forgot to include the –rm option in the command line. I fixed that now. Your suggestion to use plugin-load when starting up the server is of course also a very good alternative.

Comments are closed.