Ubuntu 16.4 上安装 MySQL:没有 root 密码提示并且没有创建 `mysql` 文件夹

Ubuntu 16.4 上安装 MySQL:没有 root 密码提示并且没有创建 `mysql` 文件夹

我的服务器硬盘崩溃了,不幸的是我的 MySQL 备份(每天一次)缺少一些重要数据,但我有文件夹中的文件/var/lib/mysql

在 Ubuntu 16.4 上的新安装中,我成功安装了 MySQL 并尝试将文件从旧安装复制/var/lib/mysql到新安装,但是遇到了问题并决定重新安装 MySQL。

我已经关注这些说明可以完全卸载并重新安装 MySQL但是现在当我尝试安装 MySQL 时,我看到以下输出:

user@computer:~$ sudo apt-get install mysql-server mysql-client
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following NEW packages will be installed
      mysql-client mysql-server
    0 to upgrade, 2 to newly install, 0 to remove and 0 not to upgrade.
    Need to get 0 B/20.2 kB of archives.
    After this operation, 317 kB of additional disk space will be used.
    Selecting previously unselected package mysql-client.
    (Reading database ... 213412 files and directories currently installed.)
    Preparing to unpack .../mysql-client_5.7.12-0ubuntu1_all.deb ...
    Unpacking mysql-client (5.7.12-0ubuntu1) ...
    Selecting previously unselected package mysql-server.
    Preparing to unpack .../mysql-server_5.7.12-0ubuntu1_all.deb ...
    Unpacking mysql-server (5.7.12-0ubuntu1) ...
    Setting up mysql-client (5.7.12-0ubuntu1) ...
    Setting up mysql-server (5.7.12-0ubuntu1) ...

然而:

  • 没有任何提示出现,询问数据库配置或为 MySQLroot用户设置密码
  • 沒有/etc/mysql/建立文件夾
  • 沒有/var/lib/mysql/建立文件夾

尝试卸载时mysql-common,出现以下错误:

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies.
 mysql-client : Depends: mysql-client-5.7 but it is not going to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

我该如何按照提示和正确的文件夹再次正确安装MySQL,或者如何找到默认值/etc/mysql//var/lib/mysql/文件夹内容来手动进行设置?

答案1

以下命令可以帮助我卸载并重新安装 MySQL(按此顺序,尽管我不知道其中一些命令是否是多余的):

  • sudo apt-get install mysql-client
  • sudo apt-get install mysql-server
  • sudo apt-get purge dbconfig-mysql
  • sudo apt-get purge mysql-common
  • sudo apt-get install mysql-server
  • sudo apt-get install mysql-client

相关内容