从文件备份 MySQL 数据库和用户

从文件备份 MySQL 数据库和用户

我正在使用安装了 Ubuntu 16.04 的 VPS。今天运行时sudo apt-get install git-core curl我遇到了错误:

Setting up mysql-common (5.7.15-0ubuntu0.16.04.1) ...
update-alternatives: error: alternative path /etc/mysql/my.cnf.fallback doesn't exist
dpkg: error processing package mysql-common (--configure):
 subprocess installed post-installation script returned error exit status 2
dpkg: dependency problems prevent configuration of libmysqlclient20:amd64:
 libmysqlclient20:amd64 depends on mysql-common (>= 5.5); however:
  Package mysql-common is not configured yet.

dpkg: error processing package libmysqlclient20:amd64 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of libdbd-mysql-perl:No apport report written because the error message indicates its a followup error from a previous failure.

 libdbd-mysql-perl depends on libmysqlclient20 (>= 5.7.11); however:
  Package libmysqlclient20:amd64 is not configured yet.

dpkg: error processing package libdbd-mysql-perl (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of mysql-client-5.6:No apport report written because the error message indicates its a followup error from a previous failure.

 mysql-client-5.6 depends on libdbd-mysql-perl (>= 1.2202); however:
  Package libdbd-mysql-perl is not configured yet.
 mysql-client-5.6 depends on mysql-common (>= 5.5); however:
  Package mysql-common is not configured yet.

dpkg: error processing package mysql-client-5.6 (--configure):
 dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                                              Errors were encountered while processing:
 mysql-common
 libmysqlclient20:amd64
 libdbd-mysql-perl
 mysql-client-5.6

我发现我的 mysql 包可能已损坏,我必须修复它们。由于我托管的 Jira、Confluence 和 Bitbucket 应用程序的兼容性原因,我正在运行较旧的 mysql 5.6 版本。

我尝试了几种解决方案来解决该问题,但sudo dpkg -r mysql-common命令过程中一切都失败了。

dpkg: dependency problems prevent removal of mysql-common:
 libmysqlclient20:amd64 depends on mysql-common (>= 5.5).
 mysql-client-5.6 depends on mysql-common (>= 5.5); however:
  Package mysql-common is to be removed.

dpkg: error processing package mysql-common (--remove):
 dependency problems - not removing
Errors were encountered while processing:
 mysql-common

在完全不了解自己在做什么的情况下,我用sudo apt-get remove --purge命令删除了 mysql-server。一切都没有解决问题mysql-common

通过命令全新安装 mysqlsudo apt install mysql-server-5.6也会导致问题mysql-common

我觉得我能做的最后一件事是完全删除与 mysql 相关的文件,但在此之前我必须备份我的用户和数据库。

我无法使用 mysqldump。是否有可能仅通过处理文件来备份所有内容?

答案1

是的。但是您应该记下最后使用 mysql 数据目录的版本,因为仅通过复制文件无法迁移到较新的主版本。因此,请备份您的 mysql 数据目录 - 以防万一。为了安全起见,我会创建一个单独的 tar.gz 存档。然后您有几种选择。

  • 删除所有冲突的软件包,然后使用软件包管理器安装合适的软件包。如果后者的版本与您之前使用的 mysql 服务器不同,则需要每个数据库的 mysql 转储。
  • 如果您的包管理器无法明确提供此版本,那么获取它们的最简单方法是从源构建所需版本的 mysql 服务器,将其安装在自定义前缀中并手动启动它,指向您的 mysql 数据目录,然后执行转储。

相关内容