从 CentOS 7 或 RHEL 7 中完全删除 MariaDB 或 MySQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33362904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:21:32  来源:igfitidea点击:

Completely remove MariaDB or MySQL from CentOS 7 or RHEL 7

mysqlcentosmariadbyumrhel

提问by Stack Over

I installed MariaDB on CentOS 7 but I had some problems with some configuration, now it is completely misconfigured.

我在 CentOS 7 上安装了 MariaDB,但我在某些配置上遇到了一些问题,现在它完全配置错误。

Thus, I wanted to remove the MariaDB with “yum remove mariadb mariadb-server”, after that I reinstalled it with “yum install mariadb mariadb-server”.

因此,我想用“yum remove mariadb mariadb-server”删除MariaDB,然后我用“yum install mariadb mariadb-server”重新安装它。

Unfortunately, the configuration remains. It seems as if yum remove don't delete all MariaDB Config-Files.

不幸的是,配置仍然存在。似乎 yum remove 不会删除所有 MariaDB 配置文件。

How can I remove MariaDB completely from CentOS 7?

如何从 CentOS 7 中完全删除 MariaDB?

回答by Ciprian Stoica

These steps are working on CentOS 6.5 so they should work on CentOS 7 too:

这些步骤适用于 CentOS 6.5,因此它们也适用于 CentOS 7:

(EDIT- exactly the same steps work for MariaDB 10.3 on CentOS 8)

编辑- 在 CentOS 8 上,MariaDB 10.3 的步骤完全相同)

  1. yum remove mariadb mariadb-server
  2. rm -rf /var/lib/mysqlIf your datadirin /etc/my.cnfpoints to a different directory, remove that directory instead of /var/lib/mysql
  3. rm /etc/my.cnfthe file might have already been deleted at step 1
  4. Optional step: rm ~/.my.cnf
  5. yum install mariadb mariadb-server
  1. yum remove mariadb mariadb-server
  2. rm -rf /var/lib/mysql如果您DATADIR/etc/my.cnf中指向不同的目录,删除该目录,而不是在/ var / lib中/ MySQL的
  3. rm /etc/my.cnf该文件可能已在步骤 1 中被删除
  4. 可选步骤: rm ~/.my.cnf
  5. yum install mariadb mariadb-server

[EDIT] - Update for MariaDB 10.1 on CentOS 7

[编辑] - 在 CentOS 7 上更新 MariaDB 10.1

The steps above worked for CentOS 6.5 and MariaDB 10.

上述步骤适用于 CentOS 6.5 和 MariaDB 10。

I've just installed MariaDB 10.1 on CentOS 7 and some of the steps are slightly different.

我刚刚在 CentOS 7 上安装了 MariaDB 10.1,其中一些步骤略有不同。

Step 1 would become:

步骤 1 将变为:

yum remove MariaDB-server MariaDB-client

Step 5 would become:

第 5 步将变为:

yum install MariaDB-server MariaDB-client

The other steps remain the same.

其他步骤保持不变。

回答by Trevor

To update and answer the question without breaking mail servers. Later versions of CentOS 7 have MariaDB included as the base along with PostFix which relies on MariaDB. Removing using yum will also remove postfix and perl-DBD-MySQL. To get around this and keep postfix in place, first make a copy of /usr/lib64/libmysqlclient.so.18 (which is what postfix depends on) and then use:

在不破坏邮件服务器的情况下更新和回答问题。CentOS 7 的更高版本包含 MariaDB 作为基础以及依赖于 MariaDB 的 PostFix。使用 yum 删除也会删除 postfix 和 perl-DBD-MySQL。为了解决这个问题并保持 postfix 到位,首先复制 /usr/lib64/libmysqlclient.so.18(这是 postfix 所依赖的),然后使用:

rpm -qa | grep mariadb

then remove the mariadb packages using (changing to your versions):

然后使用(更改为您的版本)删除 mariadb 包:

rpm -e --nodeps "mariadb-libs-5.5.56-2.el7.x86_64"
rpm -e --nodeps "mariadb-server-5.5.56-2.el7.x86_64"
rpm -e --nodeps "mariadb-5.5.56-2.el7.x86_64"

Delete left over files and folders (which also removes any databases):

删除剩余的文件和文件夹(这也会删除任何数据库):

rm -f?/var/log/mariadb
rm -f /var/log/mariadb/mariadb.log.rpmsave
rm -rf?/var/lib/mysql
rm -rf?/usr/lib64/mysql
rm -rf?/usr/share/mysql

Put back the copy of /usr/lib64/libmysqlclient.so.18 you made at the start and you can restart postfix.

把你在开始时做的/usr/lib64/libmysqlclient.so.18 的副本放回去,你可以重新启动postfix。

There is more detail at https://code.trev.id.au/centos-7-remove-mariadb-replace-mysql/which describes how to replace mariaDB with MySQL

https://code.trev.id.au/centos-7-remove-mariadb-replace-mysql/ 中有更多详细信息,其中描述了如何用 MySQL 替换 mariaDB

回答by CRTLBREAK

systemd

系统

sudo systemctl stop mysqld.service && sudo yum remove -y mariadb mariadb-server && sudo rm -rf /var/lib/mysql /etc/my.cnf

sysvinit

sysvinit

sudo service mysql stop && sudo apt-get remove mariadb mariadb-server && sudo rm -rf /var/lib/mysql /etc/my.cnf