お問い合わせ

ブログ

これまでに経験してきたプロジェクトで気になる技術の情報を紹介していきます。

CentOSへMySqlをインストール

okuda Okuda 2 years

1.ユーザ変更 rootユーザになります。

sudo su

2.Mysql8リポジトリ MySQLリポジトリの設定をします。

rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm

3.MySQL8をインストール MySQLリポジトリには複数のMySQLバージョンがあるため、すべてのMySQLリポジトリを無効にし、MySQL8リポジトリのみを有効にします。

sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/mysql-community.repo
# 出力
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                                                                                                       | 9.7 kB  00:00:00     
 * base: d36uatko69830t.cloudfront.net
 * epel: nrt.edge.kernel.org
 * extras: d36uatko69830t.cloudfront.net
 * remi-php72: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * updates: d36uatko69830t.cloudfront.net
base                                                                                                                                                                                       | 3.6 kB  00:00:00     
epel                                                                                                                                                                                       | 4.7 kB  00:00:00     
extras                                                                                                                                                                                     | 2.9 kB  00:00:00     
mysql80-community                                                                                                                                                                          | 2.6 kB  00:00:00     
remi-php72                                                                                                                                                                                 | 3.0 kB  00:00:00     
remi-safe                                                                                                                                                                                  | 3.0 kB  00:00:00     
updates                                                                                                                                                                                    | 2.9 kB  00:00:00     
(1/6): epel/x86_64/group_gz                                                                                                                                                                |  95 kB  00:00:00     
(2/6): epel/x86_64/updateinfo                                                                                                                                                              | 1.0 MB  00:00:00     
(3/6): epel/x86_64/primary_db                                                                                                                                                              | 6.9 MB  00:00:00     
(4/6): mysql80-community/x86_64/primary_db                                                                                                                                                 | 128 kB  00:00:00     
(5/6): remi-php72/primary_db                                                                                                                                                               | 243 kB  00:00:00     
(6/6): remi-safe/primary_db                                                                                                                                                                | 1.8 MB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:8.0.22-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 8.0.22-1.el7 for package: mysql-community-server-8.0.22-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 8.0.11 for package: mysql-community-server-8.0.22-1.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: mysql-community-server-8.0.22-1.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: mysql-community-server-8.0.22-1.el7.x86_64
--> Processing Dependency: libaio.so.1()(64bit) for package: mysql-community-server-8.0.22-1.el7.x86_64
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
---> Package mysql-community-client.x86_64 0:8.0.22-1.el7 will be installed
--> Processing Dependency: mysql-community-client-plugins = 8.0.22-1.el7 for package: mysql-community-client-8.0.22-1.el7.x86_64
--> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.11 for package: mysql-community-client-8.0.22-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:8.0.22-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: mysql-connector-odbc-5.2.5-8.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:net-snmp-agent-libs-5.7.2-49.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:mariadb-devel-5.5.68-1.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:net-snmp-5.7.2-49.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: mysql-connector-odbc-5.2.5-8.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 1:net-snmp-agent-libs-5.7.2-49.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.68-1.el7 for package: 1:mariadb-devel-5.5.68-1.el7.x86_64
---> Package mysql-community-client-plugins.x86_64 0:8.0.22-1.el7 will be installed
---> Package mysql-community-libs.x86_64 0:8.0.22-1.el7 will be obsoleting
--> Running transaction check
---> Package mariadb-devel.x86_64 1:5.5.68-1.el7 will be obsoleted
---> Package mysql-community-devel.x86_64 0:8.0.22-1.el7 will be obsoleting
---> Package mysql-community-libs-compat.x86_64 0:8.0.22-1.el7 will be obsoleting
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================================================================================
 Package                                                         Arch                                    Version                                         Repository                                          Size
==================================================================================================================================================================================================================
Installing:
 mysql-community-devel                                           x86_64                                  8.0.22-1.el7                                    mysql80-community                                  8.1 M
     replacing  mariadb-devel.x86_64 1:5.5.68-1.el7
 mysql-community-libs                                            x86_64                                  8.0.22-1.el7                                    mysql80-community                                  4.6 M
     replacing  mariadb-libs.x86_64 1:5.5.68-1.el7
 mysql-community-libs-compat                                     x86_64                                  8.0.22-1.el7                                    mysql80-community                                  1.2 M
     replacing  mariadb-libs.x86_64 1:5.5.68-1.el7
 mysql-community-server                                          x86_64                                  8.0.22-1.el7                                    mysql80-community                                  510 M
Installing for dependencies:
 libaio                                                          x86_64                                  0.3.109-13.el7                                  base                                                24 k
 mysql-community-client                                          x86_64                                  8.0.22-1.el7                                    mysql80-community                                   48 M
 mysql-community-client-plugins                                  x86_64                                  8.0.22-1.el7                                    mysql80-community                                  235 k
 mysql-community-common                                          x86_64                                  8.0.22-1.el7                                    mysql80-community                                  616 k

Transaction Summary
==================================================================================================================================================================================================================
Install  4 Packages (+4 Dependent packages)

Total download size: 572 M
Is this ok [y/d/N]: y
Downloading packages:
(1/8): libaio-0.3.109-13.el7.x86_64.rpm                                                                                                                                                    |  24 kB  00:00:00     
warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm is not installed
(2/8): mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm                                                                                                                              | 235 kB  00:00:00     
(3/8): mysql-community-common-8.0.22-1.el7.x86_64.rpm                                                                                                                                      | 616 kB  00:00:00     
(4/8): mysql-community-devel-8.0.22-1.el7.x86_64.rpm                                                                                                                                       | 8.1 MB  00:00:00     
(5/8): mysql-community-libs-8.0.22-1.el7.x86_64.rpm                                                                                                                                        | 4.6 MB  00:00:00     
(6/8): mysql-community-libs-compat-8.0.22-1.el7.x86_64.rpm                                                                                                                                 | 1.2 MB  00:00:00     
(7/8): mysql-community-client-8.0.22-1.el7.x86_64.rpm                                                                                                                                      |  48 MB  00:00:01     
(8/8): mysql-community-server-8.0.22-1.el7.x86_64.rpm                                                                                                                                      | 510 MB  00:00:06     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                              79 MB/s | 572 MB  00:00:07     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql80-community-release-el7-3.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : mysql-community-common-8.0.22-1.el7.x86_64                                                                                                                                                    1/10 
  Installing : mysql-community-client-plugins-8.0.22-1.el7.x86_64                                                                                                                                            2/10 
  Installing : mysql-community-libs-8.0.22-1.el7.x86_64                                                                                                                                                      3/10 
  Installing : mysql-community-client-8.0.22-1.el7.x86_64                                                                                                                                                    4/10 
  Installing : libaio-0.3.109-13.el7.x86_64                                                                                                                                                                  5/10 
  Installing : mysql-community-server-8.0.22-1.el7.x86_64                                                                                                                                                    6/10 
  Installing : mysql-community-devel-8.0.22-1.el7.x86_64                                                                                                                                                     7/10 
  Installing : mysql-community-libs-compat-8.0.22-1.el7.x86_64                                                                                                                                               8/10 
  Erasing    : 1:mariadb-devel-5.5.68-1.el7.x86_64                                                                                                                                                           9/10 
  Erasing    : 1:mariadb-libs-5.5.68-1.el7.x86_64                                                                                                                                                           10/10 
  Verifying  : mysql-community-libs-8.0.22-1.el7.x86_64                                                                                                                                                      1/10 
  Verifying  : mysql-community-server-8.0.22-1.el7.x86_64                                                                                                                                                    2/10 
  Verifying  : mysql-community-client-plugins-8.0.22-1.el7.x86_64                                                                                                                                            3/10 
  Verifying  : mysql-community-common-8.0.22-1.el7.x86_64                                                                                                                                                    4/10 
  Verifying  : mysql-community-devel-8.0.22-1.el7.x86_64                                                                                                                                                     5/10 
  Verifying  : mysql-community-client-8.0.22-1.el7.x86_64                                                                                                                                                    6/10 
  Verifying  : mysql-community-libs-compat-8.0.22-1.el7.x86_64                                                                                                                                               7/10 
  Verifying  : libaio-0.3.109-13.el7.x86_64                                                                                                                                                                  8/10 
  Verifying  : 1:mariadb-devel-5.5.68-1.el7.x86_64                                                                                                                                                           9/10 
  Verifying  : 1:mariadb-libs-5.5.68-1.el7.x86_64                                                                                                                                                           10/10 

Installed:
  mysql-community-devel.x86_64 0:8.0.22-1.el7       mysql-community-libs.x86_64 0:8.0.22-1.el7       mysql-community-libs-compat.x86_64 0:8.0.22-1.el7       mysql-community-server.x86_64 0:8.0.22-1.el7      

Dependency Installed:
  libaio.x86_64 0:0.3.109-13.el7         mysql-community-client.x86_64 0:8.0.22-1.el7         mysql-community-client-plugins.x86_64 0:8.0.22-1.el7         mysql-community-common.x86_64 0:8.0.22-1.el7        

Replaced:
  mariadb-devel.x86_64 1:5.5.68-1.el7                                                                      mariadb-libs.x86_64 1:5.5.68-1.el7       

4.MySQLサービスの開始 インストールが完了したら、MySQLを起動して有効にします。

systemctl enable mysqld
systemctl start mysqld

5.MySQLのデフォルトrootユーザーパスワードの取得 MySQL 8をインストールした後、rootユーザーアカウントのデフォルトパスワードが作成されます。
rootユーザーの一時パスワードを取得します。

grep "A temporary password" /var/log/mysqld.log
# 出力
[Note] A temporary password is generated for root@localhost: デフォルトパスワード

[デフォルトパスワード]に表示されるパスワードをメモしてください。

6.MySQLセキュアインストール MySQLサーバーを保護するためにmysql_secure_installationを設定します。

mysql_secure_installation 

この設定でrootアカウントの現在のパスワードの入力を求められます。

# 出力
Enter password for user root:

メモしたデフォルトパスワードを入力して、Enterキーを押します。

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

New password:
Re-enter new password:

ルートのアカウントの新しいパスワードを2回入力するように求められます。   この後、いくつかの質問が表示されます。
ここでは、すべて「y」とすることをお勧めします。

# 出力と設定
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

7.mysql_native_passwordを設定 mysqlのネイティブパスワードを更新する必要があります。
mysqlを起動してください。

mysql -u root -p

パスワードを求められるのでrootユーザーに設定したパスワードをここに入力します。

# 出力
Enter password:

Mysqlにログインした後、現在のMySQLパスワードを使用して次のSQLクエリを実行する必要があります。
[パスワード]は現在のMySQLパスワードに変更してください。

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'パスワード';

7.MySQLを再起動 mysql_secure_installationを設定した後、MySQLを再起動する必要があります。

systemctl restart mysqld

以上でMySQL8がCentos7にインストールされ使用できるようになります。

CentOSへMySqlをインストール 2021-08-24 08:50:31

コメントはありません。

4682

お気軽に
お問い合わせください。

お問い合わせ
gomibako@aska-ltd.jp