Configure multiple MySQL 8.0 instances using systemd
Note: because systemd can manage multiple MySQL instances on platforms with systemd support, mysqld_multi and mysqld_multi.server are unnecessary and not installed.
To use the multi-instance feature, modify the my.cnf options file to include the key option configuration for each instance. These file locations are typical:
Add the content / etc/my.cnf to the configuration file
[mysqld@01] datadir=/var/lib/mysql01socket=/var/lib/mysql01/mysql.sockport=3307mysqlx_port=33070log-error=/var/log/ mysqld01.log [mysqld @ 02] datadir=/var/lib/mysql02socket=/var/lib/mysql02/mysql.sockport=3308mysqlx_port=33080log-error=/var/log/mysqld02.log
The copy name shown here @ is used as a delimiter because it is the only delimiter supported by systemd.
Create a data directory
Mkdir / var/lib/mysql01mkdir / var/lib/mysql02chown mysql.mysql / var/lib/mysql01chown mysql.mysql / var/lib/mysql02
The instance is then managed by regular systemd commands, such as:
Systemctl start mysqld@01systemctl start mysqld@02
To enable the instance to run at boot time:
Systemctl enable mysqld@01systemctl enable mysqld@02
The use of wildcards is also supported. For example, this command displays the status of all replica instances:
Systemctl status' mysqld@replica*'
To manage multiple MySQL instances on the same machine, systemd automatically uses different unit files:
Mysqld@.service instead of mysqld.service (RPM platform)
In the unit file, the% I and% I references are followed by the parameter @ tag and are used to manage that particular instance. For commands like this:
Systemctl start mysqld@01
Systemd uses the following command to start the server:
Mysqld-- defaults-group-suffix=@%I...
As a result, the [server], [mysqld], and [mysqld@01] option groups are read and used for the instance of the service.
Reference documentation: using systemd to manage MySQL servers