我怎样才能完全卸载 mysql-server 并重新安装?

我怎样才能完全卸载 mysql-server 并重新安装?

我最近将服务器从 12.10 升级到了 16.04。升级后(似乎一切顺利),我无法登录到我的 mysql 服务器。因此,我卸载了服务器,然后使用以下命令重新安装:

apt-get remove mysql-server
apt-get install mysql-server

然而,现在它似乎总是给我:

Renaming removed key_buffer and myisam-recover options (if present)
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
insserv: warning: script 'screen-cleanup' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `screen-cleanup'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `screen-cleanup'
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up mysql-client (5.7.16-0ubuntu0.16.04.1) ...
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
Processing triggers for systemd (229-4ubuntu11) ...
Processing triggers for ureadahead (0.100.0-19) ...
Errors were encountered while processing:
 mysql-server-5.7
 mysql-server

我尝试停止服务、卸载、清除甚至删除 /etc/mysql 和 /var/lib/mysql(当然,在备份之后)。

我完全不知道为什么现在会发生这种情况。我似乎无法恢复我的数据库数据。我注意到,每当我执行此卸载/重新安装过程时,它都不会要求我输入 mysql 密码,所以我想知道它是否没有完全卸载。

答案1

要删除所有配置文件,请使用

apt-get purge mysql-server\*
rm -rf /etc/my.cnf /etc/mysql

如果您还想删除所有数据库,那么您/var/lib/mysql也需要删除目录。

答案2

要添加其他答案,请不要忘记执行自动删除和自动清理。请尝试以下步骤:

sudo apt-get remove --purge mysql*
sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get remove dbconfig-mysql

相关内容