CentOS8でMySQLのインストールと初期設定

CentOS8でMySQLのインストールと初期設定

公式サイト

https://www.mysql.com/jp/

実行環境

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)

yumでインストール

特に細かいことをせずにyumでinstallをしてしまいます。

[root@localhost ~]# yum install mysql-server
メタデータの期限切れの最終確認: 1:01:57 時間前の 2020年09月06日 21時34分59秒 に実施しました。
依存関係が解決しました。
=======================================================================================
パッケージ Arch バージョン リポジトリー サイズ
=======================================================================================
インストール:
mysql-server x86_64 8.0.17-3.module_el8.0.0+181+899d6349 AppStream 22 M
依存関係のインストール:
mariadb-connector-c-config
noarch 3.0.7-1.el8 AppStream 13 k
mecab x86_64 0.996-1.module_el8.0.0+41+ca30bab6.9 AppStream 397 k
mysql x86_64 8.0.17-3.module_el8.0.0+181+899d6349 AppStream 11 M
mysql-common x86_64 8.0.17-3.module_el8.0.0+181+899d6349 AppStream 143 k
mysql-errmsg x86_64 8.0.17-3.module_el8.0.0+181+899d6349 AppStream 557 k
protobuf-lite x86_64 3.5.0-13.el8 Stream-AppStream 149 k

トランザクションの概要
=======================================================================================
インストール 7 パッケージ

ダウンロードサイズの合計: 33 M
インストール済みのサイズ: 216 M
これでよろしいですか? [y/N]:y

初期設定

とりあえずバージョンを確認し、起動します。
systemctl enable mysqld.service で自動起動をしていきます。

[root@localhost ~]# mysqld --version
/usr/libexec/mysqld Ver 8.0.17 for Linux on x86_64 (Source distribution)
[root@localhost ~]#
[root@localhost ~]# systemctl enable mysqld.service
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@localhost ~]# systemctl start mysqld.service
[root@localhost ~]# ps -eaf | grep mysql
mysql 33554 1 12 22:58 ? 00:00:01 /usr/libexec/mysqld --basedir=/usr
root 33639 6647 0 22:58 pts/0 00:00:00 grep --color=auto mysql

初期設定をしていきます。
パスワードは短いと怒られるので、それなりのものを用意していきます。

[root@localhost ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 50
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

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
... Failed! Error: Your password does not satisfy the current policy requirements ←パスワードが悪いとこんな感じで怒られる。

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : 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.


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でリモートログインできないようにする。
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 ←テストデータベースは残すとセキュリティに問題あるので削除
 - 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 ←変更の即時反映
Success.

All done! 

これで完了です。
接続していきます。

[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.17 Source distribution

Copyright (c) 2000, 2019, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)

後はDBを作っていきます。
ただ、これはrootで接続をしているので、新規でユーザを作り、正しく権限管理をしていきましょう。

アンインストール

これで関連含めて消えてくれます。

[root@localhost ~]# yum remove mysql

BASEカテゴリの最新記事