MySQL

Table of Contents

MySQLのインストール

MySQL公式を使用する手順のインストール

OS版のMySQL(mariadb)を無効化

# dnf module disable mariadb

MySQL公式のリポジトリをインストール

MySQL :: Download MySQL Yum RepositoryからURLを取得

# dnf localinstall https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm

MySQLのインストール

# dnf install mysql-community-server

起動設定

# systemctl enable mysqld
# systemctl start mysqld

接続確認

mysqld.logファイルから初期パスワードを検索します。

# grep 'temporary password' /var/log/mysqld.log
2025-04-06T11:52:30.813880Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: CI9)?%zX7g<m

検索でに使ったパスワードで接続確認
※")"が含まれているので"’"でおパスワードを囲って実行

# mysql -uroot -p'CI9)?%zX7g<m'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.4

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

初期設定

mysql_secure_installationの実行

  • rootアカウントの パスワードを設定
  • 匿名ユーザーアカウントを削除
  • リモートからのrootユーザーのログインを禁止
  • testデータベースの削除
    基本的には全てYesと答えれば良いらしい
# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

New password: 

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

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
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
 - 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!

ポートのオープン

# firewall-cmd --zone=internal --add-service=mysql --permanent
# firewall-cmd --reload
# firewall-cmd --list-all --zone=internal

動作確認

rootのログオン
# mysql -u root -p
Enter password:(rootのパスワード)
ユーザの作成
mysql> CREATE USER 'hoge'@'localhost' IDENTIFIED BY '(パスワード)';
権限の付与
mysql> grant select,insert,delete,update,create,drop,file,alter,index on *.* to hoge@localhost;

参考URL

MySQLのインストール・設定方法
MySQL 8.0 を CentOS 8.1 にインストールする手順 #Linux – Qiita

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です