Skip to main content
Manage MySQL databases, users and privileges. Requires the mysql CLI executable on the target host(s). All operations in this module take four optional arguments:
  • mysql_user: the username to connect to mysql to
  • mysql_password: the password for the connecting user
  • mysql_host: the hostname of the server to connect to
  • mysql_port: the port of the server to connect to

Functions

mysql.sql

Execute arbitrary SQL against MySQL.

mysql.user

Add/remove/update MySQL users.
Hostname: this + user makes the username - so changing this will create a new user, rather than update users with the same user.Password: will only be applied if the user does not exist - ie pyinfra cannot detect if the current password doesn’t match the one provided, so won’t attempt to change it.

mysql.database

Add/remove MySQL databases.

mysql.privileges

Add/remove MySQL privileges for a user, either global, database or table specific.

mysql.dump

Dump a MySQL database into a .sql file. Requires mysqldump.

mysql.load

Load .sql file into a database.

Examples