Mysql
services.mysql.configFile
Override the configuration file used by MySQL. By default,
NixOS generates one automatically from {option}services.mysql.settings
.
Type: path
Default
'' A configuration file automatically generated by NixOS.''
Example
`#!nix pkgs.writeText "my.cnf" '' [mysqld] datadir = /var/lib/mysql bind-address = 127.0.0.1 port = 3336
!includedir /etc/mysql/conf.d/ ''; `
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.dataDir
The data directory for MySQL.
::: {.note}
If left as the default value of /var/lib/mysql
this directory will automatically be created before the MySQL
server starts, otherwise you are responsible for ensuring the directory exists with appropriate ownership and permissions.
:::
Type: path
Example
"/var/lib/mysql"
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.enable
Whether to enable MySQL server.
Type: boolean
Default
false
Example
true
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.ensureDatabases
Ensures that the specified databases exist. This option will never delete existing databases, especially not when the value of this option is changed. This means that databases created once through this option or otherwise have to be removed manually.
Type: list of string
Default
[ ]
Example
["nextcloud""matomo"]
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.ensureUsers
Ensures that the specified users exist and have at least the ensured permissions. The MySQL users will be identified using Unix socket authentication. This authenticates the Unix user with the same name only, and that without the need for a password. This option will never delete existing users or remove permissions, especially not when the value of this option is changed. This means that users created and permissions assigned once through this option or otherwise have to be removed manually.
Type: list of (submodule)
Default
[ ]
Example
[{name = "nextcloud";ensurePermissions = {"nextcloud.*" = "ALL PRIVILEGES";};}{name = "backup";ensurePermissions = {"*.*" = "SELECT, LOCK TABLES";};}]
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.ensureUsers.*.ensurePermissions
Permissions to ensure for the user, specified as attribute set. The attribute names specify the database and tables to grant the permissions for, separated by a dot. You may use wildcards here. The attribute values specfiy the permissions to grant. You may specify one or multiple comma-separated SQL privileges here.
For more information on how to specify the target
and on which privileges exist, see the
GRANT syntax.
The attributes are used as GRANT ${attrName} ON ${attrValue}
.
Type: attribute set of string
Default
{ }
Example
{"database.*" = "ALL PRIVILEGES";"*.*" = "SELECT, LOCK TABLES";}
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.ensureUsers.*.name
Name of the user to ensure.
Type: string
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.group
Group account under which MySQL runs.
::: {.note} If left as the default value this group will automatically be created on system activation, otherwise you are responsible for ensuring the user exists before the MySQL service starts. :::
Type: string
Default
"mysql"
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.initialDatabases
List of database names and their initial schemas that should be used to create databases on the first startup of MySQL. The schema attribute is optional: If not specified, an empty database is created.
Type: list of (submodule)
Default
[ ]
Example
[{ name = "foodatabase"; schema = ./foodatabase.sql; }{ name = "bardatabase"; }]
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.initialDatabases.*.name
The name of the database to create.
Type: string
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.initialDatabases.*.schema
The initial schema of the database; if null (the default), an empty database is created.
Type: null or path
Default
null
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.initialScript
A file containing SQL statements to be executed on the first startup. Can be used for granting certain permissions on the database.
Type: null or path
Default
null
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.package
Which MySQL derivation to use. MariaDB packages are supported too.
Type: package
Example
pkgs.mariadb
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.replication.masterHost
Hostname of the MySQL master server.
Type: string
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.replication.masterPassword
Password of the MySQL replication user.
Type: string
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.replication.masterPort
Port number on which the MySQL master server runs.
Type: 16 bit unsigned integer; between 0 and 65535 (both inclusive)
Default
3306
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.replication.masterUser
Username of the MySQL replication user.
Type: string
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.replication.role
Role of the MySQL server instance.
Type: one of "master", "slave", "none"
Default
"none"
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.replication.serverId
Id of the MySQL server instance. This number must be unique for each instance.
Type: signed integer
Default
1
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.replication.slaveHost
Hostname of the MySQL slave server.
Type: string
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.settings
MySQL configuration. Refer to https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html, https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html, and https://mariadb.com/kb/en/server-system-variables/ for details on supported values.
::: {.note}
MySQL configuration options such as --quick
should be treated as
boolean options and provided values such as true
, false
,
1
, or 0
. See the provided example below.
:::
Type: attribute set of section of an INI file (attrs of INI atom (null, bool, int, float or string) or a list of them for duplicate keys)
Default
{ }
Example
{mysqld = {key_buffer_size = "6G";table_cache = 1600;log-error = "/var/log/mysql_err.log";plugin-load-add = [ "server_audit" "ed25519=auth_ed25519" ];};mysqldump = {quick = true;max_allowed_packet = "16M";};}
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix
services.mysql.user
User account under which MySQL runs.
::: {.note} If left as the default value this user will automatically be created on system activation, otherwise you are responsible for ensuring the user exists before the MySQL service starts. :::
Type: string
Default
"mysql"
Declared by: https://github.com/nixos/nixpkgs/blob/master/nixos/modules/services/databases/mysql.nix