Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use MySQL Server managed by Systemd

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article focuses on "how to use MySQL Server managed by Systemd". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use MySQL Server managed by Systemd.

The rpm package of the mysql 5.7official website, the-DWITH_SYSTEMD=bool parameter is specified at compile time, systemd management is enabled, and mysqld_safe and System V initialization scripts are not installed

-DWITH_SYSTEMD=1

If you want to use two more methods of mysqld_safe:

1. Download source package compilation

Select version: 5.7.23

Select operating system: Source Code

Select OS Version: Gerneric Linux (Architecture Independent)

Mysql-boost-5.7.23.tar.gz

two。 Download tar files or compressed tar files (files after installation, which can be started directly after decompression)

Select version: 5.7.23

Select operating system: Red Hat Enterprise Linux / Oracle Linux

Select OS Version: Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86 camera 64murbit)

Mysql-5.7.23-el7-x86_64.tar.gz / mysql-5.7.23-el7-x86_64.tar

Overview systemd:

Systemctl {start | stop | restart | status} mysqld

The instructions for compatible System V are as follows

Service mysqld {start | stop | restart | status}

# set mysql to boot automatically

Systemctl enable mysqld

Configure systemd for mysql

Add or change the options for systemd for mysqld as follows:

Systemd profile using partial (localized)

Set the systemd environment variable for the MySQL server process

Set MYSQLD_OPTS systemd variabl

1) use partial systemd configuration files

Create a directory: / etc/systemd/system/mysqld.service.d

Create a file in the directory that contains [Service], such as override.conf

[Service]

LimitNOFILE=max_open_files

PIDFile=/path/to/pid/file

Nice=nice_level

LimitCore=core_file_limit

Environment= "LD_PRELOAD=/path/to/malloc/library"

Environment= "TZ=time_zone_setting"

The new version of systemd supports the following command editing

Systemctl edit mysqld

After editing, don't forget to reload the systemd configuration and restart the mysqld service

Systemctl daemon-reload

Systemctl restart mysqld

In systemd, you must use the override.conf configuration file to get the parameters instead of the [mysqld] and [mysqld_safe] options in the previous mysql option file (/ etc/my.cnf). It will not read these two options.

For additional information about using systemd rather than mysqld_safe, see Migrating from mysqld_safe to systemd.

You can set the following parameters through override.conf:

1.PIDFILE specifies the pid file

2.LimitNOFILE, which sets the valid number of mysql server file descriptors instead of mysqld_safe 's-- open-files-limit

3. LimitCore, set the maximum kernel file size instead of mysqld_safe 's-- core-file-size

4.Nice, set the priority of mysql server scheduling instead of-- nice option for mysqld_safE

5.LD_PRELOAD, specify mysql server memory allocation library, Environment= "LD_PRELOAD=/path/to/malloc/library"

6.TZ, set the default time zone Environment= "TZ=time_zone_setting"

There are several ways to specify the environment variables of mysql server, under the management of systemd.

1. In the override.conf configuration file, use the Environment line to specify, such as: Environment= "TZ=xx"

2. / etc/sysconfig/mysql specifies the variable value

LD_PRELOAD=/path/to/malloc/library

TZ=time_zone_setting

Remember to restart mysql after modification

Systemctl restart mysqld

3.set / unset systemd variable: MYSQLD_OPTS

Systemctl set-environment MYSQLD_OPTS= "--general_log=1"

Systemctl unset-environment MYSQLD_OPTS

MYSQLD_OPTS can also be set in the / etc/sysconfig/mysql file

Remember to restart mysql after modification

Systemctl restart mysqld

Note: on systemd platforms, empty data directories will automatically initialize data when mysql server starts.

NO_INIT=true

Specify NO_INIT=true in / etc/sysconfig/mysql to control that the database is not initialized automatically.

Configure multi-instance MySQL in systemd environment

Rpm platform: / etc/my.cnf

For example, for two instances: replica01 and replica02, the configuration file is as follows:

[mysqld@replica01]

Datadir=/var/lib/mysql-replica01

Socket=/var/lib/mysql-replica01/mysql.sock

Port=3307

Log-error=/var/log/mysqld-replica01.log

[mysqld@replica02]

Datadir=/var/lib/mysql-replica02

Socket=/var/lib/mysql-replica02/mysql.sock

Port=3308

Log-error=/var/log/mysqld-replica02.log

The management methods are as follows:

Systemctl start mysqld@replica01

Systemctl start mysqld@replica02

Set up boot boot

Systemctl enable mysqld@replica01

Systemctl enable mysqld@replica02

Support for wildcard characters

Systemctl status' mysqld@replica*'

The unit file unit file of systemd is also different.

Mysqld@.service rather than mysqld.service

If you want to configure each instance separately in / etc/my.cnf.d, you need to add it in / etc/my.cnf

! includedir / etc/my.cnf.d introduces my.cnf.d 's files.

At this point, I believe you have a deeper understanding of "how to use MySQL Server managed by Systemd". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report