1. 概要
「Ubuntu 22.04」へ「MySQL」をインストールする機会があったので、記録を残しておきます。
2. インストール
パッケージの更新を行っておきます。
sudo apt update
sudo apt upgrade -y
インストール。
sudo apt install -y mysql-server
インストールが終わった時点で、サービス登録され、起動しているようです。
sudo systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2025-11-18 08:50:43 UTC; 7min ago
Process: 669 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 746 (mysqld)
Status: "Server is operational"
Tasks: 37 (limit: 4558)
Memory: 426.2M
CPU: 12.456s
CGroup: /system.slice/mysql.service
mq746 /usr/sbin/mysqld
Nov 18 08:50:39 ubuntu2204 systemd[1]: Starting MySQL Community Server...
Nov 18 08:50:43 ubuntu2204 systemd[1]: Started MySQL Community Server.
バージョンは、下記の通りでした。
mysql --version
mysql Ver 8.0.43-0ubuntu0.22.04.2 for Linux on x86_64 ((Ubuntu))
3. mysql_secure_installation
これは、「MySQL」をインストールしたことのある人には、おなじみの作業です。
スクリプトを実行して初期化します。
初期化時にパスワード等を設定するのが正式な設定方法です。
sudo mysql_secure_installation
プロンプトに従って入力して進めていきます。
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No:
パスワードのレベルを決めますかってんで y Enter で進めます。
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:
パスワードのレベルを 0, 1, 2 のいずれかで入力します(レベルは後述)。
4. 参考サイト
本ページは、「ChatGPT」軍曹を参考にさせていただきました。