Mysqlを完全に削除してMariaDB10をインストールする方法

独立していて一般的に使用されている人気のあるデータベースツールがいくつかあります。 通常、同じポートを使用しない場合は、同じサーバー上で2つの異なるリレーショナルデータベース管理システム(RDBMS)を使用できますが、サーバーのリソースを最大限に使用するかどうかはお勧めしません。 通常は、各サーバーに各RDBMSをインストールするか、必要に応じてデータを保持した後で不要なRDBMSをアンインストールして、新しいRDBMSをインストールすることをお勧めします。

最後のポイントは、MariaDBとMySqlの2つのRDBMSでも機能しません。 MariaDBをインストールするには、MySqlを削除する必要がありますが、LinuxマシンでのMySQLのアンインストールで問題が発生する場合があります。

このチュートリアルでは、Centos7サーバーにMariaDB10をインストールするために、MySQLを完全かつ適切にアンインストールする方法を説明します。

問題を理解する

MySQLパッケージを削除してMariaDBをインストールしようとすると、システムはMySQLを再インストールしようとします。 MariaDBが廃止されたことを示すエラーメッセージが表示され、システムは代わりにMySqlを再インストールしようとします。

# yum install MariaDB-server MariaDB-client -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.linode.com
 * epel: mirrors.kernel.org
 * extras: mirrors.linode.com
 * rpmforge: mirrors.evowise.com
 * updates: mirrors.linode.com
Resolving Dependencies
--> Running transaction check
---> Package MariaDB-client.x86_64 0:10.1.26-1.el7.centos will be installed
--> Processing Dependency: MariaDB-common for package: MariaDB-client-10.1.26-1.el7.centos.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: MariaDB-client-10.1.26-1.el7.centos.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: MariaDB-client-10.1.26-1.el7.centos.x86_64
...............................
...............................

Dependencies Resolved

======================================================================================================================================================
 Package                                 Arch                    Version                                     Repository                          Size
======================================================================================================================================================
Installing:
 MariaDB-client                          x86_64                  10.1.26-1.el7.centos                        mariadb                             39 M
 MariaDB-server                          x86_64                  10.1.26-1.el7.centos                        mariadb                            103 M
 MariaDB-shared                          x86_64                  10.1.26-1.el7.centos                        mariadb                            1.3 M
     replacing  mariadb-libs.x86_64 1:5.5.52-1.el7
 mysql-community-libs                    x86_64                  5.6.37-2.el7                                mysql56-community                  2.0 M
     replacing  mariadb-libs.x86_64 1:5.5.52-1.el7
Installing for dependencies:
 MariaDB-common                          x86_64                  10.1.26-1.el7.centos                        mariadb                            123 k
 boost-program-options                   x86_64                  1.53.0-26.el7                               base                               156 k
 galera                                  x86_64                  25.3.20-1.rhel7.el7.centos                  mariadb                            8.0 M
 jemalloc                                x86_64                  3.6.0-1.el7                                 epel                               105 k
 libaio                                  x86_64                  0.3.109-13.el7                              base                                24 k
 mysql-community-common                  x86_64                  5.6.37-2.el7                                mysql56-community                  257 k

Transaction Summary
........................
........................
Total                                                                                                                 2.7 MB/s | 3.5 MB  00:00:01     
Running transaction check
Running transaction test

Transaction check error:
  file /usr/share/mysql/charsets/Index.xml conflicts between attempted installs of mysql-community-common-5.6.37-2.el7.x86_64 and MariaDB-common-10.1.26-1.el7.centos.x86_64
  file /usr/share/mysql/charsets/armscii8.xml conflicts between attempted installs of mysql-community-common-5.6.37-2.el7.x86_64 and MariaDB-common-10.1.26-1.el7.centos.x86_64
  file /usr/share/mysql/charsets/ascii.xml conflicts between attempted installs of mysql-community-common-5.6.37-2.el7.x86_64 and MariaDB-common-10.1.26-1.el7.centos.x86_64

その場合、最初にシステムからMySQLを完全にアンインストールし、古いインストールのすべての設定を消去してから、独自のリポジトリを追加してMariaDBをインストールする必要があります。

1)mysqlを完全にアンインストールします

まず、MySqlとそのすべての依存関係を適切にアンインストールする必要があります

# yum list installed | grep mysql
mysql-community-client.x86_64          5.6.37-2.el7                   @mysql56-community
mysql-community-common.x86_64          5.6.37-2.el7                   @mysql56-community
mysql-community-libs.x86_64            5.6.37-2.el7                   @mysql56-community
mysql-community-release.noarch         el7-5                          installed 
mysql-community-server.x86_64          5.6.37-2.el7                   @mysql56-community

依存関係のあるパッケージを削除するには、remove-with-leavesというyumプラグインをインストールする必要があります。 インストールするには、次のように入力します。

# yum install yum-plugin-remove-with-leaves

次に、依存関係を持つパッケージを削除します。yumremove package_name–remove-leaves以下のように

# yum remove mysql-server --remove-leaves
Loaded plugins: fastestmirror, remove-with-leaves
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.37-2.el7 will be erased
--> Finished Dependency Resolution
removing libaio-0.3.109-13.el7.x86_64. It is not required by anything else.
removing mysql-community-client-5.6.37-2.el7.x86_64. It is not required by anything else.
removing mysql-community-libs-5.6.37-2.el7.x86_64. It is not required by anything else.
removing mysql-community-common-5.6.37-2.el7.x86_64. It is not required by anything else.
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be erased
---> Package mysql-community-client.x86_64 0:5.6.37-2.el7 will be erased
---> Package mysql-community-common.x86_64 0:5.6.37-2.el7 will be erased
---> Package mysql-community-libs.x86_64 0:5.6.37-2.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================
 Package                                   Arch                      Version                              Repository                             Size
======================================================================================================================================================
Removing:
 libaio                                    x86_64                    0.3.109-13.el7                       @base                                  38 k
 mysql-community-client                    x86_64                    5.6.37-2.el7                         @mysql56-community                     89 M
 mysql-community-common                    x86_64                    5.6.37-2.el7                         @mysql56-community                    2.1 M
 mysql-community-libs                      x86_64                    5.6.37-2.el7                         @mysql56-community                    9.2 M
 mysql-community-server                    x86_64                    5.6.37-2.el7                         @mysql56-community                    251 M

また、mysql-community-releaseリポジトリをアンインストールする必要があります

# yum remove mysql-community-release-el7-5
Loaded plugins: fastestmirror, remove-with-leaves
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-release.noarch 0:el7-5 will be erased
--> Finished Dependency Resolution

2)MySQLディレクトリを削除します

次に、MySQLのデフォルトのデータディレクトリを削除する必要があります /var/lib/mysql 私たちのシステムから。 デフォルトの場所にディレクトリが表示されない場合は、ディレクトリが他の場所に変更されたことを意味します。 /etc/my.cnf 変数datadirを持つファイル。

この場合、削除します /var/lib/mysql システムからのディレクトリですが、既存のファイルのバックアップを保持するために名前を変更することをお勧めします。 インストールディレクトリを完全にクリーンアップします。

# rm -rf /var/lib/mysql/
# rm -rf /etc/my.cnf

3)MariaDB10をインストールします

MariaDB 10をインストールするには、サーバーにリポジトリを追加する必要があります。 下にMariaDBリポジトリファイルを作成します /etc/yum.repos.d/MariaDB.repo 以下の内容で

[mariadb]
name = MariaDB
baseurl = https://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

これでパッケージをインストールできます

# yum install MariaDB-server MariaDB-client
Loaded plugins: fastestmirror, remove-with-leaves
Loading mirror speeds from cached hostfile
 * base: mirrors.linode.com
 * epel: mirrors.kernel.org
 * extras: mirrors.linode.com
 * rpmforge: mirrors.evowise.com
 * updates: mirrors.linode.com
Resolving Dependencies
--> Running transaction check
---> Package MariaDB-client.x86_64 0:10.1.26-1.el7.centos will be installed
--> Processing Dependency: MariaDB-common for package: MariaDB-client-10.1.26-1.el7.centos.x86_64
---> Package MariaDB-server.x86_64 0:10.1.26-1.el7.centos will be installed
--> Processing Dependency: galera for package: MariaDB-server-10.1.26-1.el7.centos.x86_64
--> Running transaction check
---> Package MariaDB-common.x86_64 0:10.1.26-1.el7.centos will be installed
---> Package galera.x86_64 0:25.3.20-1.rhel7.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================
 Package                             Arch                        Version                                           Repository                    Size
======================================================================================================================================================
Installing:
 MariaDB-client                      x86_64                      10.1.26-1.el7.centos                              mariadb                       39 M
 MariaDB-server                      x86_64                      10.1.26-1.el7.centos                              mariadb                      103 M
Installing for dependencies:
 MariaDB-common                      x86_64                      10.1.26-1.el7.centos                              mariadb                      123 k
 galera                              x86_64                      25.3.20-1.rhel7.el7.centos                        mariadb                      8.0 M

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

Total size: 150 M
Total download size: 150 M
Installed size: 647 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): MariaDB-10.1.26-centos7-x86_64-client.rpm                                                                               |  39 MB  00:00:02     
(2/3): galera-25.3.20-1.rhel7.el7.centos.x86_64.rpm                                                                            | 8.0 MB  00:00:01     
(3/3): MariaDB-10.1.26-centos7-x86_64-server.rpm                                                                               | 103 MB  00:00:12     
------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                  12 MB/s | 150 MB  00:00:12     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : MariaDB-common-10.1.26-1.el7.centos.x86_64                                                                                         1/4 
  Installing : MariaDB-client-10.1.26-1.el7.centos.x86_64                                                                                         2/4 
  Installing : galera-25.3.20-1.rhel7.el7.centos.x86_64                                                                                           3/4 
  Installing : MariaDB-server-10.1.26-1.el7.centos.x86_64  

以下のようにステータスを確認できます

# yum list installed | grep mariadb
MariaDB-client.x86_64             10.1.26-1.el7.centos   @mariadb               
MariaDB-common.x86_64             10.1.26-1.el7.centos   @mariadb               
MariaDB-server.x86_64             10.1.26-1.el7.centos   @mariadb               
MariaDB-shared.x86_64             10.1.26-1.el7.centos   @mariadb               

MySQLとMariaDBを同じサーバーにインストールすることはできません。 したがって、完全なアンインストールを行う必要があります。 MariaDBをインストールするときに、MySQLをインストールするために削除する必要がある場合は、リポジトリを削除することを忘れないでください。削除しないと、MySQLをインストールできなくなります。

関連記事: CentOS7にMariaDBをインストールする2つの方法