とある技術者の闘病記と勉強録

ブログ名の通り、技術と英語勉強についてつらつら書いてます。

Ubuntu Linux MySQL8インストール

 Linuxインストール、Apacheインストールに続き、MySQLインストール編になります。

 

fireghostman.hatenablog.com

fireghostman.hatenablog.com

 

sshでログインしたら、まずはsu、そしてインストール。

$ su
Password:
# apt install mysql-server

〜中略〜

After this operation, 246 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

 

246MBしか使わないんですねぇ。

ちなみにメモリ使用量ですが、素のLinuxだけだと256MBぐらい、

apache入れて512、SQL入れちゃうと1GBぐらいになっちゃいました。(うろ覚え)

 

自動的に入れ終わりましてサービス起動確認。

# systemctl status mysql
mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
Active: active (running) since Mon 2020-07-20 11:03:16 UTC; 49s ago
Main PID: 30712 (mysqld)
Status: "Server is operational"
Tasks: 39 (limit: 997)
Memory: 325.4M
CGroup: /system.slice/mysql.service
└─30712 /usr/sbin/mysqld

 

そしたらMYSQLの設定です。

# 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

 

パスワードに複雑性を求めるか、を聞いています。

昨今のセキュリティ事情ならYesでしょう。

 

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

 

パスワードの強度ですね。自分は0にしちゃいました。


Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

 

入れたパスワードで良いか聞かれますので、Yで。


By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

 

インストールの時に使ったanonymousユーザーを消すか、です。Yですね。


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

 

root のネットワークからの接続禁止。Yで。


Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

 

最初から作られるTESTデータベースを消すか。Yで。

 

- Dropping test database...
Success.

- Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

 

これまでの設定変更を読み込み直すか聞かれます。Yで。

 

Success.

 

All done!

 

終わりました!ではSQLに繋いでみますか。


# mysql

 

mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;

〜中略〜

| root | | auth_socket | localhost |

 

rootの認証に auth_socket が使われているわけですが、これだと

外部プログラムからのアクセスが色々と面倒らしく、caching_sha2_password

に変えることにします。

 

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'xxx';
Query OK, 0 rows affected (0.02 sec)

 

そしたら変更を反映させます。

 

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

mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
〜中略〜
| root | 省略 | caching_sha2_password | localhost |


変わりました。

 

 

mysql> exit
Bye
# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

 

あら、ユーザーパスワード入れないとダメか。

 

# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.20-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> SELECT user FROM mysql.user;
+------------------+
| user |
+------------------+
| debian-sys-maint |
| mysql.infoschema |
| mysql.session |
| mysql.sys |
| root |
+------------------+
5 rows in set (0.00 sec)

mysql> SELECT CURRENT_USER();
+----------------+
| CURRENT_USER() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

mysql> exit
Bye
#

 

この様にセットアップできました。残すはPHP