MySQL users and databases

This module provides tools for creating MySQL users and databases.


fabtools.mysql.query(query, use_sudo=True, **kwargs)[source]

Run a MySQL query.

Manage users

fabtools.mysql.user_exists(name, host='localhost', **kwargs)[source]

Check if a MySQL user exists.

fabtools.mysql.create_user(name, password, host='localhost', **kwargs)[source]

Create a MySQL user.


import fabtools

# Create DB user if it does not exist
if not fabtools.mysql.user_exists('dbuser'):
    fabtools.mysql.create_user('dbuser', password='somerandomstring')

Manage databases

fabtools.mysql.database_exists(name, **kwargs)[source]

Check if a MySQL database exists.

fabtools.mysql.create_database(name, owner=None, owner_host='localhost', charset='utf8', collate='utf8_general_ci', **kwargs)[source]

Create a MySQL database.


import fabtools

# Create DB if it does not exist
if not fabtools.mysql.database_exists('myapp'):
    fabtools.mysql.create_database('myapp', owner='dbuser')