如何彻底删除 MySQL 以进行全新安装

如何彻底删除 MySQL 以进行全新安装

我需要彻底删除有关 MySQL 的所有内容。它没有启动,所以我决定删除它。但是在安装过程中发生了以下情况:

sta@daPC:~$ sudo apt-get install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libdbd-mysql-perl libmysqlclient18 mysql-client-5.6 mysql-common
  mysql-server-5.6
Suggested packages:
  mailx tinyca
The following NEW packages will be installed:
  libdbd-mysql-perl libmysqlclient18 mysql-client-5.6 mysql-common
  mysql-server mysql-server-5.6
0 upgraded, 6 newly installed, 0 to remove and 87 not upgraded.
Need to get 0 B/12,0 MB of archives.
After this operation, 101 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Preconfiguring packages ...
Selecting previously unselected package mysql-common.
(Reading database ... 188526 files and directories currently installed.)
Preparing to unpack .../mysql-common_5.6.28-0ubuntu0.15.10.1_all.deb ...
Unpacking mysql-common (5.6.28-0ubuntu0.15.10.1) ...
Selecting previously unselected package libmysqlclient18:i386.
Preparing to unpack .../libmysqlclient18_5.6.28-0ubuntu0.15.10.1_i386.deb ...
Unpacking libmysqlclient18:i386 (5.6.28-0ubuntu0.15.10.1) ...
Selecting previously unselected package libdbd-mysql-perl.
Preparing to unpack .../libdbd-mysql-perl_4.028-2_i386.deb ...
Unpacking libdbd-mysql-perl (4.028-2) ...
Selecting previously unselected package mysql-client-5.6.
Preparing to unpack .../mysql-client-5.6_5.6.28-0ubuntu0.15.10.1_i386.deb ...
Unpacking mysql-client-5.6 (5.6.28-0ubuntu0.15.10.1) ...
Processing triggers for man-db (2.7.4-1) ...
Setting up mysql-common (5.6.28-0ubuntu0.15.10.1) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Selecting previously unselected package mysql-server-5.6.
(Reading database ... 188621 files and directories currently installed.)
Preparing to unpack .../mysql-server-5.6_5.6.28-0ubuntu0.15.10.1_i386.deb ...
Unpacking mysql-server-5.6 (5.6.28-0ubuntu0.15.10.1) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.6.28-0ubuntu0.15.10.1_all.deb ...
Unpacking mysql-server (5.6.28-0ubuntu0.15.10.1) ...
Processing triggers for man-db (2.7.4-1) ...
Processing triggers for ureadahead (0.100.0-19) ...
ureadahead will be reprofiled on next reboot
Processing triggers for systemd (225-1ubuntu9) ...
Setting up libmysqlclient18:i386 (5.6.28-0ubuntu0.15.10.1) ...
Setting up libdbd-mysql-perl (4.028-2) ...
Setting up mysql-client-5.6 (5.6.28-0ubuntu0.15.10.1) ...
Setting up mysql-server-5.6 (5.6.28-0ubuntu0.15.10.1) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
2016-02-17 04:13:48 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-02-17 04:13:48 0 [Note] /usr/sbin/mysqld (mysqld 5.6.28-0ubuntu0.15.10.1) starting as process 13491 ...

如您所见,它卡在重新启动 MySQL 服务器。我该如何删除 MySQL完全地进行全新安装?

编辑:重启电脑后问题自行解决。由于我既检测不到问题,也找不到实际解决方案,因此我没有将其作为答案发布。

答案1

我找到了解决方案:https://stackoverflow.com/questions/25244606/completely-remove-mysql-ubuntu-14-04-lts/28113482#28113482

sudo rm -rf /var/lib/mysql/mysql
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get install mysql-server

在重新安装过程中,系统提示我输入(新)密码。在上次重新安装失败时,我将其留空,而 mysql 保留了上次安装时忘记的旧密码,我以为它是空的。

答案2

dpkg -P 软件包应彻底清除包,包括配置文件。以下是选项的描述人dpkg命令

-r,--remove,-P,--purge 包...|-a|--pending 删除已安装的软件包。-r 或 --remove 删除除 conffiles 之外的所有内容。这可以避免以后重新安装软件包时必须重新配置软件包。(Conffiles 是 DEBIAN/conffiles 控制文件中列出的配置文件)。-P 或 --purge 删除所有内容,包括 conffiles。如果给出 -a 或 --pending 而不是软件包名称,则所有已解压但在文件 /var/lib/dpkg/status 中标记为要删除或清除的软件包将分别被删除或清除。注意:某些配置文件可能不为 dpkg 所知,因为它们是通过配置脚本单独创建和处理的。在这种情况下,dpkg 不会自行删除它们,但软件包的 postrm 脚本(由 dpkg 调用)必须在清除期间负责删除它们。当然,这仅适用于系统目录中的文件,而不适用于写入各个用户主目录的配置文件。

答案3

您必须使用清除:

   remove
       remove is identical to install except that packages are removed
       instead of installed. Note the removing a package leaves its
       configuration files in system. If a plus sign is appended to the
       package name (with no intervening space), the identified package
       will be installed instead of removed.

   purge
       purge is identical to remove except that packages are removed and
       purged (any configuration files are deleted too).

   --purge
       Use purge instead of remove for anything that would be removed. An
       asterisk ("*") will be displayed next to packages which are
       scheduled to be purged.  remove --purge is equivalent for purge
       command. Configuration Item: APT::Get::Purge.

句法:

 sudo apt-get remove --purge <package-name>

或者其等价物:

 sudo apt-get purge <package-name>

希望能帮助到你。

相关内容