WSL2 Ubuntu20.04にMySQLをインストールする

WSL2 Ubuntu20.04にMySQLをインストールする

Microsoftの公式ドキュメントを読むのが確実ですが、必要なコマンドだけここに紹介しておきます。

公式ドキュメント:Windows Subsystem for Linux でデータベースを使ってみる

想定する環境
  • ホストOS:Windows10 Build 19042
  • WSL2:Ubuntu20.04
  • MySQL:8.0.25

目次 非表示

MySQLのインストール

コマンドだけ紹介します。

# パッケージのインストール
$ sudo apt install mysql-server

# MySQLの起動状況確認
$ sudo service mysql status
 * MySQL is stopped.

# (MySQLが停止している場合は起動)
$ sudo /etc/init.d/mysql start

# 改めて起動状況を確認
$ sudo service mysql status
 * /usr/bin/mysqladmin  Ver 8.0.25-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
...
Threads: 2  Questions: 8  Slow queries: 0  Opens: 436  Flush tables: 3  Open tables: 27  Queries per second avg: 1.600

# rootパスワードの設定
$ sudo mysql_secure_installation

# mysqlへの接続
$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.25-0ubuntu0.20.04.1 (Ubuntu)

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.

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

mysql>...

WSLは本当に便利です。