percona\mysql\database

September 16, 2025 ยท View on GitHub

Manage Percona MySQL databases and execute SQL queries on them. Works with Percona Server 8.0+ (where supported). Establishes a control connection to the Percona server using the percona client (ensure it is installed before using this resource).

Terminology: This resource uses inclusive terms (source/replica) matching upstream MySQL. See README for details.

See test suite examples in test/fixtures/cookbooks/test/recipes/user_database.rb.

Actions

  • create - (default) to create a named database
  • drop - to drop a named database
  • query - to execute a SQL query

Properties

NameTypesDescriptionDefaultRequired?
userStringthe username of the control connectionrootno
passwordStringpassword of the user used to connect tono
hostStringhost to connect tolocalhostno
portStringport of the host to connect to3306no
database_nameStringthe name of the database to managename if not specifiedno
encodingStringutf8no
collationStringutf8_general_cino
sqlStringthe SQL query to executeno

When host has the value localhost, it will try to connect using a Unix socket, or TCP/IP if no socket is defined.

Examples

# Create a database
percona_mysql_database 'wordpress-cust01' do
  host '127.0.0.1'
  user 'root'
  password node['wordpress-cust01']['mysql']['initial_root_password']
  action :create
end

# Drop a database
percona_mysql_database 'baz' do
  action :drop
end

# Query a database
percona_mysql_database 'flush the privileges' do
  sql 'flush privileges'
  action :query
end

The query action will NOT select a database before running the query, nor return the actual results from the SQL query.