Add some more mysql functions, copied from rattail-fabric
This commit is contained in:
parent
9ad1716bad
commit
7590760569
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2019 Lance Edgar
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -24,7 +24,7 @@
|
|||
Fabric Library for MySQL
|
||||
"""
|
||||
|
||||
from rattail_fabric2 import apt, make_deploy
|
||||
from rattail_fabric2 import apt, make_deploy, sed
|
||||
|
||||
|
||||
deploy = make_deploy(__file__)
|
||||
|
@ -38,6 +38,23 @@ def install(c):
|
|||
apt.install(c, 'default-mysql-server')
|
||||
|
||||
|
||||
def set_bind_address(c, address):
|
||||
"""
|
||||
Configure the 'bind-address' setting with the given value.
|
||||
"""
|
||||
sed(c, '/etc/mysql/my.cnf',
|
||||
'^bind-address.*',
|
||||
'bind-address = {}'.format(address),
|
||||
use_sudo=True)
|
||||
|
||||
|
||||
def restart(c):
|
||||
"""
|
||||
Restart the MySQL database service
|
||||
"""
|
||||
c.sudo('systemctl restart mysql.service')
|
||||
|
||||
|
||||
def user_exists(c, name, host='localhost'):
|
||||
"""
|
||||
Determine if a given MySQL user exists.
|
||||
|
@ -118,6 +135,13 @@ def sql(c, sql, database='', **kwargs):
|
|||
return c.sudo("mysql --execute='{}' --batch --skip-column-names {}".format(sql, database), **kwargs)
|
||||
|
||||
|
||||
def script(c, path, database=''):
|
||||
"""
|
||||
Execute a SQL script against the given database.
|
||||
"""
|
||||
c.sudo("bash -c 'mysql {} < {}'".format(database, path))
|
||||
|
||||
|
||||
def download_db(c, name, destination=None):
|
||||
"""
|
||||
Download a database from the "current" server.
|
||||
|
|
Loading…
Reference in a new issue