This section contains best practices for setting up a MySQL database in a secure way.
For an easy setup, it is recommended to follow the default MySQL/MariaDB database creation instructions, which include creating the 'zabbix' user with full privileges on the Zabbix database. This user is the database owner that also has the necessary privileges for modifying the database structure when upgrading Zabbix.
To improve security, creating additional database roles and users with minimal privileges is recommended. These roles and users should be configured based on the principle of least privilege, that is, they should only have privileges that are essential for performing the intended functions.
Create the following roles with the corresponding privileges:
create role 'zbx_srv';
grant delete, insert, select, update on zabbix.* to 'zbx_srv';
flush privileges;
create role 'zbx_web';
grant delete, insert, select, update on zabbix.* to 'zbx_web';
flush privileges;
create role 'zbx_bckp';
grant lock tables, trigger, select on zabbix.* to 'zbx_bckp';
grant process on *.* to 'zbx_bckp';
flush privileges;
Table restoration should be performed by the database owner.
create role 'zbx_part';
grant select, alter, drop on zabbix.history to 'zbx_part';
grant select, alter, drop on zabbix.history_uint to 'zbx_part';
grant select, alter, drop on zabbix.history_str to 'zbx_part';
grant select, alter, drop on zabbix.history_text to 'zbx_part';
grant select, alter, drop on zabbix.history_log to 'zbx_part';
grant select, alter, drop on zabbix.trends to 'zbx_part';
grant select, alter, drop on zabbix.trends_uint to 'zbx_part';
-- For MariaDB: skip the next line (grant session_variables_admin on *.* to 'zbx_part';)
grant session_variables_admin on *.* to 'zbx_part';
grant select on zabbix.dbversion to 'zbx_part';
grant select,delete on zabbix.housekeeper to 'zbx_part';
flush privileges;
After creating roles, they can be assigned to users.
To assign the created user roles, create users and assign the relevant roles to them. Replace <user>
, <host>
, <role>
, and <password>
as necessary.
create user '<user>'@'<host>' identified by '<password>';
grant '<role>' to '<user>'@'<host>';
set default role '<role>' to '<user>'@'<host>';
-- For MariaDB: set default role '<role>' for '<user>'@'<host>'
flush privileges;
For example, to create and assign the role for running Zabbix server and proxy: