Select Your OS:
In this guide, you're going to learn how to use a Fabric script to automate a MySQL database installation on a remote virtual machine.
In order to complete this guide, you will need to know how to set up a local virtual machine to run the Fabric scripts against. You will also need to be familiar with setting up Virtualenv, which will allow us to install all the Fabric dependencies in an isolated virtual environment so there are no dependency conflicts with any other Python projects we set up in the future. In order to get up to speed, make sure you complete the guides in the prerequisites section.
- A 32-bit or 64-bit computer with at least 8GB of RAM. 16GB or more is recommended.
- At least 50GB of free disk space.
After completing the prerequisites, you may still be in an active Virtualenv. If the username in your terminal session is prepended with
(venv), you will want to deactivate the virtualenv by running
deactivate. For this tutorial, we're going to want to start from scratch with a new project and Virtualenv. This will allow us to install Fabric to our virtual environment rather than to the global dependencies list, and keep our system clean. Let's run some commands.
Also, the VM must be running when you run the Fabric command. If you do not have a running VM, please go through the prerequisites.
cd ~ mkdir fabric-mysql cd fabric-mysql virtualenv --python=/usr/local/lib/python2.7 venv source venv/bin/activate
For this tutorial, we're going to install Fabric version
pip install fabric==1.13.2
Create a file and name it
fabfile.py with the following contents:
Follow all of the prompts for setting a default MySQL root password, MySQL user, and MySQL password.
fab vagrant install_mysql
- Host OS: Ubuntu 16.04
- Guest OS: Ubuntu 14.04
- Vagrant versions: 1.8.1, 1.9.5, 2.0.0
- VirtualBox versions: 5.0.26, 5.1.22 r115126 (Qt5.5.1)
- Python 2.7.12
- Fabric 1.13.2
[localhost] local: vagrant global-status | grep running [localhost] local: vagrant ssh-config e48abe0 | grep IdentityFile [127.0.0.1:2222] Executing task 'install_mysql' [127.0.0.1:2222] run: install_mysql Fatal error: Host key for 127.0.0.1 did not match pre-existing key! Server's key was changed recently, or possible man-in-the-middle attack. Underlying exception: ('127.0.0.1',
, ) Aborting.
- Run the following command in the terminal:
- Rerun the
fab vagrant install_mysqlcommand. If you get the same error, you will have to manually delete the
ssh-keygen -R [127.0.0.1]:2222
mysql-client on the host.
sudo apt-get install mysql-client
Install Homebrew from https://brew.sh/.
# Install MySQL brew install mysql
And access MySQL.
mysql -hMY.VM.IP.ADDRESS -umyuser -p
- High Performance MySQL: Optimization, Backups, and Replication
- SQL in 10 Minutes, Sams Teach Yourself (4th Edition)
- SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL (3rd Edition)
- Database Design for Mere Mortals: A Hands-On Guide to Relational Database Design (3rd Edition)
- Vagrant: Up and Running: Create and Manage Virtualized Development Environments
- VirtualBox Guide for Beginners