§ Customizing the GreatSQL Configuration File Path
This document introduces how to customize the path of the GreatSQL configuration file (my.cnf) in different environments.
§ Customizing the my.cnf File Path When Installing GreatSQL with the RPM Package
After successfully installing GreatSQL with the RPM package, systemd is used to manage the GreatSQL database service by default, and the default configuration file path is /etc/my.cnf. If a configuration file with a custom path is needed, it can be achieved by modifying the systemd service configuration file.
Taking the CentOS system environment as an example, the following explains how to customize the my.cnf file path.
- View the current systemd service configuration file
cat /lib/systemd/system/mysqld.service
- Edit this service configuration file
vi /lib/systemd/system/mysqld.service
- Add the
--defaults-fileoption in theExecStartparameter to specify the custom configuration file path
- Add the
# The custom configuration file path is /opt/my.cnf
ExecStart=/usr/sbin/mysqld --defaults-file=/opt/my.cnf $MYSQLD_OPTS
2
- Save and exit the editor
- Reload the systemd configuration
systemctl daemon-reload
- Restart the GreatSQL service to make the configuration take effect
systemctl restart mysqld
View the GreatSQL log file to confirm that the custom configuration file takes effect and starts correctly.
§ Customizing the my.cnf File Path When Installing GreatSQL with the Binary Package
§ Customizing the Configuration File Path When Starting with the systemd Method
- View or create the systemd service configuration file of GreatSQL
cat /usr/lib/systemd/system/greatsql.service
If the file does not exist, a new configuration file can be created. For details, refer to: Managing GreatSQL with systemd.
- Edit this service configuration file and add the
--defaults-fileoption in theExecStartparameter
- Edit this service configuration file and add the
# The custom configuration file path is /opt/my.cnf
ExecStart=/usr/local/GreatSQL-8.4.4-5-Linux-glibc2.28-x86_64/bin/mysqld --defaults-file=/opt/my.cnf $MYSQLD_OPTS
2
- Save and exit the editor
- Reload the systemd configuration
systemctl daemon-reload
- Restart the GreatSQL service
systemctl restart greatsql
View the GreatSQL log file to confirm that the custom configuration file takes effect and starts correctly.
§ Customizing the Configuration File Path When Starting with the Command Line Method
When starting GreatSQL directly with the command line, the --defaults-file option can be used to specify the custom configuration file path:
# The custom configuration file path is /opt/my.cnf
/usr/local/GreatSQL-8.4.4-5-Linux-glibc2.28-x86_64/bin/mysqld --defaults-file=/opt/my.cnf &
2
The mysqld_safe command can also be used:
# The custom configuration file path is /opt/my.cnf
/usr/local/GreatSQL-8.4.4-5-Linux-glibc2.28-x86_64/bin/mysqld_safe --defaults-file=/opt/my.cnf &
2
View the GreatSQL log file to confirm that the custom configuration file takes effect and starts correctly.
§ Customizing the External my.cnf File Path in a Docker Container
In the Docker environment, by default, the GreatSQL container uses the configuration file bundled inside the container. If an external custom configuration file is needed, it can be achieved through Docker's volume mounting feature.
§ Method 1: Directly Replace the Container's Default Configuration File
The custom configuration file can also be directly mounted to replace the default configuration file in the container:
# The custom configuration file path is /opt/my.cnf
docker run -d \
--name greatsql \
-v /opt/my.cnf:/etc/my.cnf \
greatsql/greatsql
2
3
4
5
§ Method 2: Use docker-compose to Mount the Configuration File
If docker-compose is used to manage the container, volume mounting configuration can be added in the docker-compose.yml file:
version: '2'
services:
greatsql:
image: greatsql/greatsql
container_name: greatsql
volumes:
- /opt/my.cnf:/etc/my.cnf
2
3
4
5
6
7
Then use the following command to start the container:
docker-compose -f docker-compose.yml up -d
§ Notes
- Ensure that the path of the custom configuration file on the host machine is correct and the file has appropriate permissions;
- Parameters in the custom configuration file override parameters with the same name in the container's default configuration file;
- If the container cannot start with the custom configuration file, execute
docker logs greatsqlto view the error information, and then solve the corresponding problem based on the error prompt.
If you need to customize the default /etc/my.cnf file path in the GreatSQL container, you can modify the relevant code of the GreatSQL Docker project (opens new window) yourself. This is not described here.
Scan the QR code to follow our WeChat Official Account
