Ubuntu 22.04 LTSにMySQLをインストールする方法

環境

# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS"

MySQLのインストール手順
1.システムパッケージを更新します

# sudo apt update
# sudo apt upgrade

2.MySQL 8 をインストールします

# sudo apt install mysql-server

3.MySQL8ステータスを確認します

# sudo service mysql status
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-05-04 17:18:19 JST; 1min 12s ago

4.MySQLサーバーにログインします

# sudo mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.29-0ubuntu0.22.04.1 (Ubuntu)

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

5.新ユーザーを作成します

mysql> CREATE USER 'admin'@'localhost' IDENTIFIED BY 'A@123abc#';
Query OK, 0 rows affected (0.01 sec)

権限を付与します

mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

権限をフラッシュします。

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

6.認証方法を変更します
形式「auth_socket」から「mysql_native_password」に変更します。

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Abc445566@';
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

 

Ubuntu 22.04

Posted by arkgame