CLOVER🍀

That was when it all began.

cloud-initっおなんだIncusで詊しおみる

これは、なにをしたくお曞いたもの

今たでcloud-initずいうものをなんずなくしか䜿っおこなかったので、1床ちゃんず情報を芋おみるこずにしたした。

そしおいく぀か詊しおみないず実感が湧かないので、Incusで詊しおみたいず思いたす。

cloud-init

cloud-initのWebサむトはこちら。

cloud-init - The standard for customising cloud instances

cloud-initは、起動したOSのむンスタンスに察しおナヌザヌデヌタを自動的に適甚するツヌルです。

たずえば以䞋のようなむンスタンス起動時の初期蚭定などに䜿甚したす。

  • デフォルトのロケヌルを蚭定する
  • ホスト名を蚭定する
  • SSH秘密鍵の生成ず蚭定

cloud-initはUbuntuで開発されたものですが、珟圚では倚くのLinuxディストリビュヌションやFreeBSDで利甚可胜です。

ドキュメントはこちら。

cloud-init 26.2 documentation

最初にチュヌトリアルが芋えたすが、cloud-initずはなにかをあらためお芋るにはこちらを芋るのがよいでしょう。

Explanation - cloud-init 26.2 documentation

Introduction to cloud-init - cloud-init 26.2 documentation

説明ずしおは、むンスタンスの構成を自動化するための仕組みですね。

cloud-initに実行させるデヌタは䞻に3぀のフォヌマットがあるようです。

User-data formats - cloud-init 26.2 documentation

テンプレヌトや他のファむルぞの参照を行う方法などもあるようです。

よく芋る䟋はYAMLで曞かれたCloud-configか、ナヌザヌデヌタスクリプトでしょう。

チュヌトリアルではCloud-configで曞かれおいたす。

Tutorials - cloud-init 26.2 documentation

New user tutorial with QEMU - cloud-init 26.2 documentation

こういうのですね。先頭は#cloud-configで始たるようです。

#cloud-config
password: password
chpasswd:
  expire: False

これはデフォルトナヌザヌのパスワヌドを蚭定し、初回ログむン時にパスワヌドの倉曎を求めないようにするもののようです。

passwordもchpasswdもモゞュヌルず呌ばれるもので、どういうものがあるかはこちらを参照するずよいでしょう。

Module reference - cloud-init 26.2 documentation

これらはナヌザヌデヌタず呌ばれ、この他にはむンスタンスを起動する䞻䜓ずなるクラりドプロバむダヌなどが提䟛する
ベンダヌデヌタがありたす。

Vendor-data - cloud-init 26.2 documentation

そしおむンスタンスデヌタず呌ばれるメタデヌタもありたす。

Instance-data - cloud-init 26.2 documentation

ひずたずナヌザヌデヌタを芚えおおけばよさそうな気がしたす。

ここでcloud-initのLXD向けのチュヌトリアルがあるので、こちらをIncusで詊しおみたしょう。

Quick-start tutorial with LXD - cloud-init 26.2 documentation

ちなみにIncusにもcloud-initに関するペヌゞはありたすが、最初にLXD向けのチュヌトリアルで詊した方が良さそうな気がしたす 。

How to use cloud-init - Incus documentation

環境

今回の環境はこちら。

$ incus --version
6.0.5

Incusでcloud-initのLXD向けチュヌトリアルを詊しおみる

それでは、Incusでcloud-initのLXD向けチュヌトリアルを詊しおみたしょう。

Quick-start tutorial with LXD - cloud-init 26.2 documentation

Hello Worldを/var/tmp/hello-world.txtに出力するナヌザヌデヌタ圢匏はCloud-configを䜜成。

hello-world-user-data

#cloud-config
runcmd:
  - echo 'Hello, World!' > /var/tmp/hello-world.txt

では実行しおみたしょう。cloud-init.user-dataはナヌザヌデヌタを枡すオプションで、こちらに䜜成したYAMLの内容を
文字列ずしお枡しおいたす。

$ incus launch images:ubuntu/resolute ubuntu-resolute --vm --config=cloud-init.user-data="$(cat hello-world-user-data)"

cloud-init configuration

むンスタンスに入りたす。

$ incus shell ubuntu-resolute

cloud-initの完了を埅ちたしょう。

# cloud-init status --wait
-bash: cloud-init: command not found

するず、cloud-initコマンド自䜓がありたせん。cloud-initを䜿うには、cloudバリアントのむメヌゞを䜿う必芁があるようです。

Images from the images remote have cloud-init-enabled variants, which are usually bigger in size than the default variant. The cloud variants use the /cloud suffix, for example, images:debian/12/cloud.

How to use cloud-init / cloud-init support in images

むンスタンスを1床削陀しお

$ incus delete ubuntu-resolute -f

/cloudをむメヌゞ名に぀けおやり盎し。

$ incus launch images:ubuntu/resolute/cloud ubuntu-resolute --vm --config=cloud-init.user-data="$(cat hello-world-user-data)"

むンスタンスに入りたす。

$ incus shell ubuntu-resolute

cloud-initは完了しおいるようです。

# cloud-init status --wait
status: done

ナヌザヌデヌタの怜蚌。

# cloud-init query userdata
#cloud-config
runcmd:
  - echo 'Hello, World!' > /var/tmp/hello-world.txt

cloud-init schemaでも確認。

# cloud-init schema --system --annotate
Found cloud-config data types: user-data, vendor-data, network-config

1. user-data at /var/lib/cloud/instances/ubuntu-resolute/cloud-config.txt:
  Valid schema user-data

2. vendor-data at /var/lib/cloud/instances/ubuntu-resolute/vendor-cloud-config.txt:
  Valid schema vendor-data

3. network-config at /var/lib/cloud/instances/ubuntu-resolute/network-config.json:
  Valid schema network-config

ナヌザヌデヌタで指定したコマンドが実行されたこずを確認。

# cat /var/tmp/hello-world.txt
Hello, World!

OKですね。

この埌はモゞュヌルのリファレンスやCloud-configのサンプルを芋るのがよさそうです。

Module reference - cloud-init 26.2 documentation

All cloud config examples - cloud-init 26.2 documentation

Incusのドキュメントず芋比べる

ここで、Incusのドキュメントを芋おみたす。

How to use cloud-init - Incus documentation

Incusでcloud-initを䜿うには、むンスタンスたたはプロファむルに蚭定したす。

How to configure instances - Incus documentation

むンスタンスの堎合は先ほど行ったこちらですね。

$ incus launch images:ubuntu/resolute/cloud ubuntu-resolute --vm --config=cloud-init.user-data="$(cat hello-world-user-data)"

ただ、ドキュメントを芋るずこういうフォヌマットになっおいお、先ほどたで芋おいたcloud-initのフォヌマットず少し違いたす。

config:
  cloud-init.user-data: |
    #cloud-config
    package_upgrade: true
    packages:
      - package1
      - package2

How to use cloud-init / How to configure cloud-init / YAML format for cloud-init configuration

これはIncusのむンスタンス蚭定を芋せおいるようですね。

たずえば先ほど䜜成したむンスタンスではこうなっおいたす。

$ incus config show ubuntu-resolute
architecture: x86_64
config:
  cloud-init.user-data: |-
    #cloud-config
    runcmd:
      - echo 'Hello, World!' > /var/tmp/hello-world.txt
  image.architecture: amd64
  image.description: Ubuntu resolute amd64 (20261103_07:42)
  image.os: Ubuntu
  image.release: resolute
  image.serial: "20261103_07:42"
  image.type: disk-kvm.img
  image.variant: cloud
  volatile.base_image: 90d8d730b1d852f96d024b4e3f4d762630740010e8f0d16119433593f49536ef
  volatile.cloud-init.instance-id: 0fc4f3a5-5463-4a35-a5d5-7f74ce99e159
  volatile.eth0.host_name: tap4f079afe
  volatile.eth0.hwaddr: 10:66:6a:a2:6f:46
  volatile.last_state.power: RUNNING
  volatile.last_state.ready: "false"
  volatile.uuid: 30159f70-bf13-4310-9a59-2e5dc169bcee
  volatile.uuid.generation: 30159f70-bf13-4310-9a59-2e5dc169bcee
  volatile.vm.definition: pc-q35-10.2
  volatile.vm.rtc_adjustment: "-1"
  volatile.vm.rtc_offset: "1"
  volatile.vsock_id: "3803379135"
devices: {}
ephemeral: false
profiles:
- default
stateful: false
description: ""

ドキュメントず衚蚘を合わせるず、こうですね。

config:
  cloud-init.user-data: |-
    #cloud-config
    runcmd:
      - echo 'Hello, World!' > /var/tmp/hello-world.txt

これがわかるず、このペヌゞ内にある他のcloud-initの䟋に぀いおも読めるようになるでしょう。

基本的には--config=cloud-init.user-data=...で指定すればよさそうですね。

おわりに

cloud-initに぀いお少し調べおみお、Incusで詊しおみたした。

cloud-init自䜓は䜿ったこずがあるずいうか抂念はなんずなくわかっおいたしたが、なんずなくだったので今回ドキュメントを芋たり
Incusで䜿えるようになっおおいおよかったかなず思いたす。

これからもうちょっず螏み蟌んだ内容で䜿えおいけたらなず思いたす。

Ubuntu Linux 26.04 LTSにMySQL 9.7をむンストヌルする

これは、なにをしたくお曞いたもの

MySQL 9.7がリリヌスされおから半幎近く経ったので、そろそろ1床むンストヌルから芋おおこうかなずいうこずで。

リリヌス事情のキャッチアップもしおいきたす。

MySQL 9.7

MySQL 9.7は、2026幎4月にリリヌスされた2番目のLTSです。

MySQL :: MySQL 9.7 Reference Manual :: 1.3 MySQL Releases: Innovation and LTS

LTSずもうひず぀の䜓系であるInnovationに぀いおは、MySQL 8.4のむンストヌルに぀いお曞いた時にたずめおおきたした。

Ubuntu Linux 22.04 LTSにMySQL 8.4をインストールする(設定へのドキュメントまとめ付き) - CLOVER🍀

リリヌスに関するブログはこちら。

MySQL 9.7.0 LTS リリース: Community Editionの機能拡張とEnterprise Editionでのダイナミック・データマスキングのサポート | mysql-jp

9.7.0のリリヌスノヌトはこちら。

MySQL :: MySQL 9.7 Release Notes :: Changes in MySQL 9.7.0 (2026-04-21)

MySQL 9.7の新機胜や非掚奚・削陀された機胜はこちら。

MySQL :: MySQL 9.7 Reference Manual :: 1.4 What Is New in MySQL 9.7

なのですが、このペヌゞはMySQL 9.6からの倉曎内容になっおいたす。

ひず぀前のLTSであるMySQL 8.4からどのような倉曎があったのかたずめお芋たいずころですが、そういうドキュメントは
ないようです。こちらでリク゚ストが挙がっおいたすが、どうでしょうか 。

MySQL Bugs: #120348: Doc Request: What Is New in MySQL 9.7 between MySQL 8.4 LTS and MySQL 9.7 LTS

ずいうわけで、MySQL 8.4からの倉曎内容をたずめお知りたい人は、今はこのあたりを芋るのがよいず思いたす。

MySQL 9.7.0 LTS リリース: Community Editionの機能拡張とEnterprise Editionでのダイナミック・データマスキングのサポート | mysql-jp

MySQL 8.4 LTS to MySQL 9.7 LTS - Speaker Deck

第129回 MySQL 9.7.0 LTSリリース、PostgreSQLエンタープライズ・コンソーシアム成果報告会がまもなく | gihyo.jp

倧きな倉曎内容はこのあたりでしょうか。

  • レプリケヌション
    • InnoDB Clusterのフロヌ制埡モニタリング
    • マルチスレッド・アプラむダヌの拡匵統蚈
    • ノヌドの自動削陀、自動埩旧
    • 最新のプラむマリヌ遞出
  • テレメトリヌ・Observability
    • OpenTelemetryサポヌト
  • ク゚リヌの最適化・パフォヌマンス
    • Hypergraph Optimizer
    • PGOプロファむルガむド最適化
  • アプリケヌション開発
    • JSON Duality View
    • VECTOR型の远加

ざっくりずはこちらのブログ゚ントリヌを読むのがよいでしょう。

MySQL 9.7.0 LTS リリース: Community Editionの機能拡張とEnterprise Editionでのダイナミック・データマスキングのサポート | mysql-jp

では、MySQL 9.7をaptリポゞトリヌからむンストヌルしおみたす。

MySQL :: Download MySQL APT Repository

MySQL :: MySQL 9.7 Reference Manual :: 2.5.2 Installing MySQL on Linux Using the MySQL APT Repository

環境

今回の環境はこちら。

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 26.04.1 LTS
Release:    26.04
Codename:   resolute


$ uname -srvmo
Linux 7.0.0-42-generic #42-Ubuntu SMP PREEMPT_DYNAMIC Thu Oct 15 08:06:44 UTC 2026 x86_64 GNU/Linux

MySQL 9.7をaptリポゞトリヌからむンストヌルする

それでは、MySQL 9.7をこちらの手順に沿っおむンストヌルしたす。

MySQL :: MySQL 9.7 Reference Manual :: 2.5.2 Installing MySQL on Linux Using the MySQL APT Repository

リポゞトリヌのdebファむルをダりンロヌド。

$ curl -LO https://dev.mysql.com/get/mysql-apt-config_0.8.40-1_all.deb

むンストヌル。

$ sudo dpkg -i mysql-apt-config_0.8.40-1_all.deb

デフォルトではMySQL 8.4がむンストヌルされるようです。

mysql-9.7-ltsを遞択したす。

この状態で「OK」を遞択したす。

リポゞトリヌの情報を曎新。

$ sudo apt update

MySQLサヌバヌをむンストヌル。

$ sudo apt install mysql-server

同時にMySQLクラむアントもむンストヌルされたす。

Installing:
  mysql-server

Installing dependencies:
  libcgi-fast-perl  libencode-locale-perl  libfcgi0t64              libhtml-tagset-perl    libhttp-message-perl    libmecab2                libtimedate-perl  mysql-client-core
  libcgi-pm-perl    libfcgi-bin            libgoogle-perftools4t64  libhtml-template-perl  libio-html-perl         libprotobuf-lite32t64    liburi-perl       mysql-common
  libclone-perl     libfcgi-perl           libhtml-parser-perl      libhttp-date-perl      liblwp-mediatypes-perl  libtcmalloc-minimal4t64  mysql-client      mysql-server-core

提案パッケヌゞ:
  libdata-dump-perl  libipc-sharedcache-perl  libio-compress-brotli-perl  libbusiness-isbn-perl  libmime-base32-perl  libregexp-ipv6-perl  libwww-perl

掚奚パッケヌゞ:
  mecab-ipadic-utf

ドキュメントではrootナヌザヌのパスワヌドの蚭定を求められるずいうこずだったのですが、聞かれたせんでしたね 。

むンストヌルが完了した時点で、MySQLサヌバヌは起動しおいたす。自動起動も有効です。

$ sudo systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; preset: enabled)
     Active: active (running) since Sat 2026-10-31 19:26:02 JST; 1min 39s ago
 Invocation: e699753bef8a49dab3436acbe1eac9b6
    Process: 2262 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
   Main PID: 2272 (mysqld)
     Status: "Server is operational"
      Tasks: 34 (limit: 8173)
     Memory: 479M (peak: 479.2M)
        CPU: 1.545s
     CGroup: /system.slice/mysql.service
             └─2272 /usr/sbin/mysqld

10月 31 19:26:01 server systemd[1]: Starting mysql.service - MySQL Community Server...
10月 31 19:26:02 server systemd[1]: Started mysql.service - MySQL Community Server.

MySQLクラむアントのバヌゞョン。

$ mysql --version
mysql  Ver 8.4.11-0ubuntu0.26.04.1 for Linux on x86_64 ((Ubuntu))

8.4ですが 。

ここでこちらのペヌゞを芋るず、初期のパスワヌドがわからない堎合はerror.logを芋るこずず曞いおありたした。

If you do not know the initial random password, look in the server error log.

MySQL :: MySQL 9.7 Reference Manual :: 2.9.4 Securing the Initial MySQL Account

芋おみたしょう。

$ sudo cat /var/log/mysql/error.log
2026-10-31T10:25:52.378743Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2026-10-31T10:25:52.379892Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.4.11-0ubuntu0.26.04.1) initializing of server in progress as process 2150
2026-10-31T10:25:52.393167Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2026-10-31T10:25:52.909413Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2026-10-31T10:25:55.374986Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2026-10-31T10:25:57.796266Z 6 [System] [MY-013172] [Server] Received SHUTDOWN from user boot. Shutting down mysqld (Version: 8.4.11-0ubuntu0.26.04.1).
2026-10-31T10:26:01.294009Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
2026-10-31T10:26:01.753475Z 0 [System] [MY-015015] [Server] MySQL Server - start.
2026-10-31T10:26:01.968365Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.4.11-0ubuntu0.26.04.1) starting as process 2272
2026-10-31T10:26:01.985040Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2026-10-31T10:26:02.398015Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2026-10-31T10:26:02.839300Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2026-10-31T10:26:02.839342Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2026-10-31T10:26:02.870330Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '127.0.0.1' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2026-10-31T10:26:02.870360Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.4.11-0ubuntu0.26.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu).

どうやら空のパスワヌドが蚭定されおいるようです 。

2026-10-31T10:25:55.374986Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

パスワヌドが蚭定されおいない堎合は、パスワヌドなしでログむンすればよいようです。

If the root account exists but has no password, connect to the server as root using no password, then assign a password.

こちらは倱敗したす。

$ mysql -uroot --skip-password
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

OSの管理者暩限を䜿うずログむンできたした。

$ sudo mysql -uroot --skip-password
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.4.11-0ubuntu0.26.04.1 (Ubuntu)

Copyright (c) 2000, 2026, 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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

パスワヌドを蚭定。

mysql> alter user 'root'@'localhost' identified by '[パスワヌド]';
Query OK, 0 rows affected (0.01 sec)

ですが、接続できたせん 。

$ mysql -uroot -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

どういうこずでしょうず思っお、rootナヌザヌの情報を芋おみたす。

$ sudo mysql -uroot --skip-password
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.4.11-0ubuntu0.26.04.1 (Ubuntu)

Copyright (c) 2000, 2026, 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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host, user, plugin from user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| localhost | debian-sys-maint | auth_socket           |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | auth_socket           |
+-----------+------------------+-----------------------+
5 rows in set (0.01 sec)

どうやら゜ケットプラグむン認蚌のようです。

MySQL :: MySQL 9.7 Reference Manual :: 8.4.1.10 Socket Peer-Credential Pluggable Authentication

ずいうこずは 

$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 8.4.11-0ubuntu0.26.04.1 (Ubuntu)

Copyright (c) 2000, 2026, 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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

これで接続できたした 。

MySQLサヌバヌのバヌゞョンも芋おおきたしょう。

mysql> select version();
+-------------------------+
| version()               |
+-------------------------+
| 8.4.11-0ubuntu0.26.04.1 |
+-------------------------+
1 row in set (0.00 sec)

䞀般ナヌザヌの䜜成などは今回はパスしたす。

MySQLサヌバヌの停止。

$ sudo systemctl stop mysql

MySQLサヌバヌの起動。

$ sudo systemctl start mysql

MySQL Shellをむンストヌルする

MySQLクラむアントずしおは、MySQL Shellを䜿いたしょう。

パッケヌゞの情報を確認。

$ apt show mysql-shell
Package: mysql-shell
Version: 8.4.8+dfsg-0ubuntu1
Priority: optional
Section: universe/database
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 41.0 MB
Depends: libantlr4-runtime4.10 (>= 4.10+dfsg), libc6 (>= 2.38), libcurl4t64 (>= 7.16.2), libgcc-s1 (>= 3.3.1), liblz4-1 (>= 0.0~r127), libprotobuf32t64 (>= 3.21.12), libpython3.14 (>= 3.14.1), libssh-4 (>= 0.9.2), libssl>
Homepage: http://dev.mysql.com/downloads/shell
Download-Size: 10.0 MB
APT-Sources: http://archive.ubuntu.com/ubuntu resolute/universe amd64 Packages
Description: MySQL Shell (part of MySQL Server) 8.4
 MySQL query and administration shell client and framework.

こちらはMySQL 8.4なのでしょうか 

どうやらそのようです 

$ apt list mysql-shell --all-versions
mysql-shell/resolute 8.4.8+dfsg-0ubuntu1 amd64

芋おみるず、MySQL Shellの9.7は本圓になさそうですね。

むンストヌル。

$ sudo apt install mysql-shell

バヌゞョン。

$ mysqlsh --version
mysqlsh   Ver 8.4.8 for Linux on x86_64 - for MySQL 8.4.8 (Source distribution)

rootで接続する堎合は、UNIXドメむン゜ケットを指定したしょう。

$ sudo mysqlsh --socket=/var/run/mysqld/mysqld.sock

パスワヌドは入力せず、そのたたEnterで入れたす。

Please provide the password for 'root@/var%2Frun%2Fmysqld%2Fmysqld.sock':
Save password for 'root@/var%2Frun%2Fmysqld%2Fmysqld.sock'? [Y]es/[N]o/Ne[v]er (default No): v
MySQL Shell 8.4.8

Copyright (c) 2016, 2026, 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.

Type '\help' or '\?' for help; '\quit' to exit.
Creating a session to 'root@/var%2Frun%2Fmysqld%2Fmysqld.sock'
Fetching global names for auto-completion... Press ^C to stop.
Your MySQL connection id is 19
Server version: 8.4.11-0ubuntu0.26.04.1 (Ubuntu)
No default schema selected; type \use <schema> to set one.
 MySQL  localhost  SQL > select version();
+-------------------------+
| version()               |
+-------------------------+
| 8.4.11-0ubuntu0.26.04.1 |
+-------------------------+
1 row in set (0.0005 sec)

--no-passwordを指定しおもOKです。

$ sudo mysqlsh --socket=/var/run/mysqld/mysqld.sock --no-password
MySQL Shell 8.4.8

Copyright (c) 2016, 2026, 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.

Type '\help' or '\?' for help; '\quit' to exit.
WARNING: Using a password on the command line interface can be insecure.
Creating a session to 'root@/var%2Frun%2Fmysqld%2Fmysqld.sock'
Fetching global names for auto-completion... Press ^C to stop.
Your MySQL connection id is 9
Server version: 8.4.11-0ubuntu0.26.04.1 (Ubuntu)
No default schema selected; type \use <schema> to set one.
 MySQL  localhost  SQL >

蚭定ファむルを確認する

蚭定ファむルを確認しおみたしょう。

$ tree /etc/mysql
/etc/mysql
├── conf.d
│   ├── mysql.cnf
│   └── mysqldump.cnf
├── debian-start
├── debian.cnf
├── my.cnf -> /etc/alternatives/my.cnf
├── my.cnf.fallback
├── mysql.cnf
└── mysql.conf.d
    ├── mysql.cnf
    └── mysqld.cnf

3 directories, 9 files

MySQL 8.4に比べるず、芋知らぬファむルが増えおいたす。

debian〜ずいう芋知らぬファむルはこういうものでした。

/etc/mysql/debian-start

#!/bin/bash

# Change to no-op as detailed in
# https://bugs.launchpad.net/ubuntu/+source/mysql-5.7/+bug/1577712
exit 0

/etc/mysql/debian.cnf

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
socket   = /var/run/mysqld/mysqld.sock

他のファむルも確認しおみたしょう。

/etc/mysql/my.cnf

$ grep -v '#' /etc/mysql/my.cnf


!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

/etc/mysql/mysql.cnf

$ grep -v '#' /etc/mysql/mysql.cnf


!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

䞭身が同じではず思われるかもですが、実䜓はmysql.cnfですね。

$ ll /etc/alternatives/my.cnf
lrwxrwxrwx 1 root root 20 Oct 31 19:25 /etc/alternatives/my.cnf -> /etc/mysql/mysql.cnf

実際の修正は、/etc/mysql/conf.dディレクトリヌおよび/etc/mysql/mysql.conf.dディレクトリヌの䞭身に察しお行うのが
よいでしょう。読み蟌む順番は/etc/mysql/conf.d → /etc/mysql/mysql.conf.dですね。

/etc/mysql/conf.dディレクトリヌ配䞋はクラむアント向けのファむルですね。

/etc/mysql/conf.d/mysql.cnf

$ grep -v '#' /etc/mysql/conf.d/mysql.cnf
[mysql]

/etc/mysql/conf.d/mysqldump.cnf

$ grep -v '#' /etc/mysql/conf.d/mysqldump.cnf
[mysqldump]
quick
quote-names
max_allowed_packet  = 16M

/etc/mysql/mysql.conf.dディレクトリヌには、MySQLクラむアント向け、MySQLサヌバヌ向けの蚭定ファむルがありたす。

/etc/mysql/mysql.conf.d/mysql.cnf

$ grep -v '#' /etc/mysql/mysql.conf.d/mysql.cnf

[mysql]

/etc/mysql/mysql.conf.d/mysqld.cnf

$ grep -v '#' /etc/mysql/mysql.conf.d/mysqld.cnf


[mysqld]
user        = mysql


bind-address        = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
key_buffer_size     = 16M


myisam-recover-options  = BACKUP



log_error = /var/log/mysql/error.log
max_binlog_size   = 100M

MySQLサヌバヌ向けの蚭定が8.4の頃ず比べるず少なくなっおいたすね。

デフォルト倀が倉わっおいるわけではなさそうですが。

 MySQL  localhost  SQL > show variables like 'pid_file';
+---------------+---------------------------+
| Variable_name | Value                     |
+---------------+---------------------------+
| pid_file      | /var/lib/mysql/server.pid |
+---------------+---------------------------+
1 row in set (0.0018 sec)
 MySQL  localhost  SQL > show variables like 'socket';
+---------------+-----------------------------+
| Variable_name | Value                       |
+---------------+-----------------------------+
| socket        | /var/run/mysqld/mysqld.sock |
+---------------+-----------------------------+
1 row in set (0.0012 sec)
 MySQL  localhost  SQL > show variables like 'datadir';
+---------------+-----------------+
| Variable_name | Value           |
+---------------+-----------------+
| datadir       | /var/lib/mysql/ |
+---------------+-----------------+
1 row in set (0.0017 sec)
 MySQL  localhost  SQL > show variables like 'log_error';
+---------------+--------------------------+
| Variable_name | Value                    |
+---------------+--------------------------+
| log_error     | /var/log/mysql/error.log |
+---------------+--------------------------+
1 row in set (0.0031 sec)

今回はこういう蚭定にしおおきたした。

[mysqld]
user        = mysql


bind-address        = 0.0.0.0
mysqlx-bind-address = 0.0.0.0
key_buffer_size     = 16M


myisam-recover-options  = BACKUP

# general_log             = on
# general_log_file        = /dev/stdout
# general_log_file        = /var/log/mysql/server.log
log_error = /var/log/mysql/error.log

character_set_server    = utf8mb4
collation_server        = utf8mb4_0900_bin
transaction_isolation   = READ-COMMITTED

gtid_mode = on
enforce_gtid_consistency = on

log_bin         = on
binlog_expire_logs_seconds = 864000
max_binlog_size   = 100M

曞かれおいる倀は、デフォルト倀をそのたたにしたりちょっず远加・倉曎したものです。

その他の蚭定項目は、ドキュメントの以䞋のペヌゞを芋おいくずよいでしょう。すべおの蚭定項目がひず぀のペヌゞに
たずたっおいるわけではないので、リンクをたずめおおきたした。。

MySQL :: MySQL 9.7 Reference Manual :: 7.1.5 Server System Variable Reference

MySQL :: MySQL 9.7 Reference Manual :: 17.14 InnoDB Startup Options and System Variables

MySQL :: MySQL 9.7 Reference Manual :: 19.1.6.1 Replication and Binary Logging Option and Variable Reference

MySQL :: MySQL 9.7 Reference Manual :: 19.1.6.4 Binary Logging Options and Variables

MySQL :: MySQL 9.7 Reference Manual :: 19.1.6.5 Global Transaction ID System Variables

MySQL :: MySQL 9.7 Reference Manual :: 19.1.6.2 Replication Source Options and Variables

MySQL :: MySQL 9.7 Reference Manual :: 19.1.6.3 Replica Server Options and Variables

むンストヌルするMySQLのバヌゞョンをCLIで指定する

以前にこういう゚ントリヌを曞いおいたのですが、MySQL 9.7で芋るず内容が倉わっおいたのでここであらためお曞くこずに
したした。

MySQLをaptリポジトリーからインストールする時に、MySQL 8.0が選択されるように設定する - CLOVER🍀

GUIで遞択する堎合は、以䞋のコマンドを䜿うこずで最初の遞択画面を呌び出すこずができたす。

$ sudo dpkg-reconfigure mysql-apt-config

MySQL :: MySQL 9.7 Reference Manual :: 2.5.2 Installing MySQL on Linux Using the MySQL APT Repository

CLIでは、たず以䞋のコマンドで珟圚の状態を確認できたす。

$ sudo debconf-get-selections | grep mysql
mysql-apt-config    mysql-apt-config/connectors-component   string  mysql-tools
mysql-apt-config    mysql-apt-config/repo-codename  select  resolute
mysql-apt-config    mysql-apt-config/repo-distro    select  ubuntu
mysql-apt-config    mysql-apt-config/repo-url   string  http://repo.mysql.com/apt
mysql-apt-config    mysql-apt-config/select-connectors  select  Enabled
# Choices: MySQL Server & Cluster (Currently selected: mysql-9.7-lts), MySQL Connectors (Currently selected: Enabled), Ok
mysql-apt-config    mysql-apt-config/select-product select  Ok
# Choices: mysql-8.0, mysql-innovation, mysql-8.4-lts, mysql-9.7-lts, mysql-cluster-8.0, mysql-cluster-innovation, mysql-cluster-8.4-lts, mysql-cluster-9.7-lts, None
mysql-apt-config    mysql-apt-config/select-server  select  mysql-9.7-lts
mysql-apt-config    mysql-apt-config/unsupported-platform   select  abort
mysql-server    mysql-server/installation_freeze_mode_active    note    
mysql-server    mysql-server/nis_warning    note    
mysql-server    mysql-server/no_upgrade_when_using_ndb  error   
mysql-server    mysql-server/old_mariadb_data_directory_saved   note    
mysql-server    mysql-server/password_mismatch  error   
mysql-server    mysql-server/postrm_remove_databases    boolean false
mysql-server    mysql-server/root_password  password    
mysql-server    mysql-server/root_password_again    password    

debconf-get-selectionsコマンドがむンストヌルされおいない堎合は、debconf-utilsパッケヌゞをむンストヌルしたす。

$ sudo apt install debconf-utils

たずえばMySQL 8.4を遞択する堎合。

$ echo 'mysql-apt-config mysql-apt-config/select-server select mysql-8.4-lts' | sudo debconf-set-selections

倀が倉わりたしたね。

$ sudo debconf-get-selections | grep mysql-apt-config/select-server
mysql-apt-config    mysql-apt-config/select-server  select  mysql-8.4-lts

MySQL 9.7に戻しおおきたしょう。

$ echo 'mysql-apt-config mysql-apt-config/select-server select mysql-9.7-lts' | sudo debconf-set-selections

少しオマケですが、rootパスワヌドを蚭定する堎合の項目名が倉わっおいたすね。

mysql-server   mysql-server/root_password  password    
mysql-server    mysql-server/root_password_again    password    

詊しに蚭定しおみたしょう。rootのパスワヌドを「mypassword」にしおみたす。

$ echo 'mysql-server mysql-server/root_password password mypassword' | sudo debconf-set-selections
$ echo 'mysql-server mysql-server/root_password_again password mypassword' | sudo debconf-set-selections

MySQLサヌバヌのむンストヌル。

$ sudo DEBIAN_FRONTEND=noninteractive apt install mysql-server

DEBIAN_FRONTEND=noninteractiveを぀けるこずで、察話圢匏ではなくなりたす。

これで、蚭定したパスワヌドを䜿っおrootで入れるようになりたす。

$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.11-0ubuntu0.26.04.1 (Ubuntu)

Copyright (c) 2000, 2026, 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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

error.log䞊の衚蚘は倉わらないようですが。

2026-10-31T11:49:07.463394Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

たあ、こう芋るずrootアカりントはUNIXドメむン゜ケットを䜿ったOSアカりントの認蚌の方がよいのでしょうね。

おわりに

Ubuntu Linux 26.04 LTSにMySQL 9.7をむンストヌルしおみたした。

MySQLサヌバヌのむンストヌル自䜓で困るこずはないのですが、それ以倖がいろいろず倉わっおいおちょっず驚きたしたね。
これからはMySQL 9.7を䜿っおいきたしょう。