Deploying a new mysql server using Docker is quite easy:

docker run --name mysql mariadb

But once the server is up, you want root access to it from your command-line. The mariadb repo shows an example of how to do this. I’ve wrapped their command in a little shell function that you can add to your .bashrc or .zshrc. If you call the function without arguments, it will drop you on the mysql prompt. If you give a mysql command as argument, it will execute it as mysql root and show the result.

Here’s how it works:

# mysqlroot "SHOW DATABASES"
Database
my_db_1
my_db_2

# mysqlroot
MariaDB [(none)]>

Bonus round: automated backup