Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save msakamoto-sf/c371a8aa846d37b772fd51b297689e55 to your computer and use it in GitHub Desktop.
Save msakamoto-sf/c371a8aa846d37b772fd51b297689e55 to your computer and use it in GitHub Desktop.
CentOS Stream 8 に Python 3.9 と MysQL 8 を dnf でインストールするメモ

Python 3.9 を AppStream からインストール

参考:

[msakamoto@ip-10-0-2-15 ~]$ sudo dnf module list | grep python
libselinux-python    2.8              common                                   Python 2 bindings for libselinux
python27             2.7 [d]          common [d]                               Python programming language, version 2.7
python36             3.6 [d]          build, common [d]                        Python programming language, version 3.6
python38             3.8 [d]          build, common [d]                        Python programming language, version 3.8
python39             3.9 [d]          build, common [d]                        Python programming language, version 3.9

[msakamoto@ip-10-0-2-15 ~]$ sudo dnf module -y install  python39
(...)
Installed:
  python39-3.9.7-1.module_el8.6.0+930+10acc06f.x86_64                         python39-libs-3.9.7-1.module_el8.6.0+930+10acc06f.x86_64
  python39-pip-20.2.4-6.module_el8.6.0+930+10acc06f.noarch                    python39-pip-wheel-20.2.4-6.module_el8.6.0+930+10acc06f.noarch
  python39-setuptools-50.3.2-4.module_el8.6.0+930+10acc06f.noarch             python39-setuptools-wheel-50.3.2-4.module_el8.6.0+930+10acc06f.noarch

[msakamoto@ip-10-0-2-15 ~]$ rpm -ql python39
/usr/bin/pydoc-3
/usr/bin/pydoc3
/usr/bin/pydoc3.9
/usr/bin/python3
/usr/bin/python3.9
/usr/bin/unversioned-python
/usr/lib/.build-id
/usr/lib/.build-id/c4
/usr/lib/.build-id/c4/379682d3c6d0f38ba30b967aaee27374a80fc2
/usr/share/doc/python39
/usr/share/doc/python39/README.rst
/usr/share/man/man1/python.1.gz
/usr/share/man/man1/python3.1.gz
/usr/share/man/man1/python3.9.1.gz

[msakamoto@ip-10-0-2-15 ~]$ python3 -V
Python 3.9.7

[msakamoto@ip-10-0-2-15 ~]$ rpm -ql python39-pip
/usr/bin/pip-3
/usr/bin/pip-3.9
/usr/bin/pip3
/usr/bin/pip3.9
/usr/lib/python3.9/site-packages/pip

MySQL 8 をインストール

参考:

パッケージインストール

[msakamoto@ip-10-0-2-15 ~]$ sudo dnf module list | grep mysql
mysql                8.0 [d]          client, server [d]                       MySQL Module

[msakamoto@ip-10-0-2-15 ~]$ sudo dnf info mysql-server
Last metadata expiration check: 0:28:56 ago on Sat 05 Feb 2022 09:54:33 PM JST.
Available Packages
Name         : mysql-server
Version      : 8.0.26
Release      : 1.module_el8.4.0+915+de215114
Architecture : x86_64
Size         : 25 M
Source       : mysql-8.0.26-1.module_el8.4.0+915+de215114.src.rpm
Repository   : appstream
Summary      : The MySQL server and related files
URL          : http://www.mysql.com
License      : GPLv2 with exceptions and LGPLv2 and BSD
Description  : MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
             : client/server implementation consisting of a server daemon (mysqld)
             : and many different client programs and libraries. This package contains
             : the MySQL server and some accompanying files and directories.

→ 8.0 系が提供されてるので、そのままdnfでインストール。

[msakamoto@ip-10-0-2-15 ~]$ sudo dnf install -y mysql mysql-server

[msakamoto@ip-10-0-2-15 ~]$ rpm -ql mysql-server
/etc/logrotate.d/mysqld
/etc/my.cnf.d/mysql-default-authentication-plugin.cnf
/etc/my.cnf.d/mysql-server.cnf
/run/mysqld
/usr/bin/ibd2sdi
/usr/bin/innochecksum
/usr/bin/my_print_defaults
/usr/bin/myisam_ftdump
/usr/bin/myisamchk
/usr/bin/myisamlog
/usr/bin/myisampack
/usr/bin/mysql_migrate_keyring
/usr/bin/mysql_secure_installation
/usr/bin/mysql_ssl_rsa_setup
/usr/bin/mysql_tzinfo_to_sql
/usr/bin/mysql_upgrade
/usr/bin/mysqld_pre_systemd
/usr/bin/mysqldumpslow
/usr/bin/perror
/usr/lib/.build-id
(...)
/usr/lib/systemd/system/mysqld.service
/usr/lib/systemd/system/mysqld@.service
/usr/lib/tmpfiles.d/mysqld.conf
(...)
/usr/libexec/mysqld
/usr/sbin/mysqld
(...)
/usr/share/man/man1/mysql_secure_installation.1.gz
(...)
/usr/share/man/man8/mysqld.8.gz
(...)
/var/lib/mysql
(...)
/var/log/mysql
/var/log/mysql/mysqld.log

設定ファイルの構成

  • 依存関係でインストールされる mariadb-connector-c-config/etc/my.cnf および /etc/my.cnf.d/ ディレクトリが含まれている。
    • /etc/my.cnf から、 /etc/my.cnf.d/ 以下の設定ファイルを include している。
  • サーバ用の設定ファイルは /etc/my.cnf.d/mysql-server.cnf で、mysql-server パッケージが提供している。
  • mysqld --verbose --help によると /etc/my.cnf を読み込み [mysqld], [server], [mysqld-8.0] セクションを読み込む。
    • つまり MySQL では client/server とも /etc/my.cnf を共通で読み込み、その中のセクション名でそれぞれ毎の設定値を読み分けている。
  • カスタマイズする際は独自の [server] セクションで設定値をカスタムしたファイルを /etc/my.cnf.d/ 以下に配置するのが流儀と思われる。

設定ファイル/systemd unitファイル/helpの詳細:

  • /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
  • /etc/my.cnf.d/mysql-server.cnf
#
# This group are read by MySQL server.
# Use it for options that only the server (but not clients) should see
#
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html

# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
  • /usr/lib/systemd/system/mysqld.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades.  If you want to customize, the
# best way is to use systemctl edit:
#
# $ systemctl edit mysqld.service
#
# this will create file
#
#  /etc/systemd/system/mysqld.service.d/override.conf
#
# which be parsed after the file mysqld.service itself is parsed.
#
# For example, if you want to increase mysql's open-files-limit to 20000
# add following when editing with command above:
#
#       [Service]
#       LimitNOFILE=20000
#
# Or if you require to execute pre and post scripts in the unit file as root, set
#       PermissionsStartOnly=true
#
# For more info about custom unit files, see systemd.unit(5) or
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F
#
# Don't forget to reload systemd daemon after you change unit configuration:
# root> systemctl --system daemon-reload

[Unit]
Description=MySQL 8.0 database server
After=syslog.target
After=network.target

[Service]
Type=notify
User=mysql
Group=mysql

ExecStartPre=/usr/libexec/mysql-check-socket
ExecStartPre=/usr/libexec/mysql-prepare-db-dir %n
# Note: we set --basedir to prevent probes that might trigger SELinux alarms,
# per bug #547485
ExecStart=/usr/libexec/mysqld --basedir=/usr
ExecStartPost=/usr/libexec/mysql-check-upgrade
ExecStopPost=/usr/libexec/mysql-wait-stop

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

# Place temp files in a secure directory, not /tmp
PrivateTmp=true

Restart=on-failure

RestartPreventExitStatus=1

# Sets open_files_limit
LimitNOFILE = 10000

# Set enviroment variable MYSQLD_PARENT_PID. This is required for SQL restart command.
Environment=MYSQLD_PARENT_PID=1

[Install]
WantedBy=multi-user.target
  • mysqld --verbose --help ( mysqld(8) では細かい説明が無く、 --help を参照せよ、となっている)
mysqld  Ver 8.0.26 for Linux on x86_64 (Source distribution)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Starts the MySQL database server.

Usage: mysqld [OPTIONS]

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
The following groups are read: mysqld server mysqld-8.0
(...)

インストール後の初期設定

  1. $ sudo vi /etc/my.cnf.d/charset.cnf
# デフォルトの文字コードを設定
# 絵文字等 4 バイト長の文字を扱う場合は [utf8mb4]
[mysqld]
character-set-server = utf8mb4

[client]
default-character-set = utf8mb4
  1. $ sudo systemctl enable mysqld
  2. $ sudo systemctl start mysqld

この後は 参考資料 と同様に $ sudo mysql_secure_installation を実行して MySQL 用rootユーザのパスワードを設定、匿名ユーザは削除、リモートPCからのroot接続を禁止、テスト用DBの削除を実施、DB作成/TABLE作成/SELECT/DROP動作を確認した。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment