清除後無法重新安裝 mysql-server

清除後無法重新安裝 mysql-server

我最近全新安裝了 Ubuntu 16.04。我還通過安裝了mysql-serverand mysql-client(它們的預設版本 5.7.12)apt-get install

由於 5.7.12 顯示了一些問題,我決定卸載它。我apt-get remove mysql-server mysql-client首先嘗試過,但發現像/etc/mysql和一樣的工件/var/lib/mysql沒有被刪除。

然後我嘗試了apt-get --purge removed mysql-server mysql-client,但仍然沒有區別。

因此,我手動刪除了它們(通過rm -rf)。我還手動刪除了*mysql*來自/usr/任何mysql-*依賴包(例如mysql-common.

然而,現在,當我想重新安裝時mysql-server and -client,我發現我不能。

其實我現在就處於一個既不能apt-get remove mysql-server也不能的狀態apt-get install mysql-server

如何解決我所處的情況?如果我的本機套件儲存庫元資料已損壞,該如何修復它?

我不想再重新安裝整個作業系統以及所有其他應用程式和環境,只是因為mysql-server.

例如,以下是我嘗試刪除時收到的錯誤mysql-server

$ apt-get remove  mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libaio1 mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  mysql-server
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 159 kB disk space will be freed.
Do you want to continue? [Y/n] 
(Reading database ... 237601 files and directories currently installed.)
Removing mysql-server (5.7.12-0ubuntu1) ...
Setting up mysql-server-5.7 (5.7.12-0ubuntu1) ...
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
Errors were encountered while processing:
 mysql-server-5.7
E: Sub-process /usr/bin/dpkg returned an error code (1)

當嘗試安裝時,我收到此錯誤:

$ apt-get -f install mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  mysql-server
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 0 B/10.1 kB of archives.
After this operation, 159 kB of additional disk space will be used.
Selecting previously unselected package mysql-server.
(Reading database ... 237599 files and directories currently installed.)
Preparing to unpack .../mysql-server_5.7.12-0ubuntu1_all.deb ...
Unpacking mysql-server (5.7.12-0ubuntu1) ...
Setting up mysql-server-5.7 (5.7.12-0ubuntu1) ...
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
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
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

這是輸出apt-get install -f

$ apt-get install -f 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up mysql-server-5.7 (5.7.12-0ubuntu1) ...
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
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
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

2017 年 1 月 10 日編輯:這是對這篇文章的主要審查,以糾正這篇文章中的嚴重問題。

內心的錯誤

問題是該軟體包仍然在系統上處於半安裝和半配置狀態,需要明確刪除。

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

它的真正意思是,該套件mysql-server-5.7是 的依賴項mysql-server,已安裝,但尚未配置。所以你需要purge它來去除那些留下的麵包屑mysql-server-5.7

sudo apt purge mysql-server mysql-server-5.7

基本原理

當您使用安裝軟體時apt,它也會自動為您處理依賴項。

當您刪除某些套件時,它可能無法處理這些相同的依賴項。就本文而言,該依賴項是mysql-server-5.7.

您可以透過發出以下命令來檢查套件狀態。

dpkg-query -l [package-name-here]

通常,如果您看到代碼unrc套件名稱左側的代碼,您可以判斷它是否確實是損壞的套件。

當我遇到這個問題時,它是與libapache2-mod-phplibapache2-mod-php7.0。這是我的輸出。

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                        Version            Architecture       Description
+++-===========================-==================-==================-============================================================
un  libapache2-mod-php          <none>             <none>             (no description available)

就我而言,它聲稱我的軟體包的狀態未知,而且它沒有安裝un在我的系統上(程式碼)。

當您告訴apt某些內容時remove,它可能會留下軟體包、設定檔和其他在自動安裝過程中可能出現問題的項目。

當你告訴apt某件事purge它確實發生時,最好清除remove可能留下的任何麵包屑。

我最初聲明我假設該進程仍在運行,但很可能它處於非活動狀態或已死亡。

檢查該服務是否幹擾您的軟體包刪除的最佳方法是先檢查該服務。

1) 調查mysql服務

使用 給我們的系統錯誤apt,我們實際上可以透過檢查服務systemctl的狀態來調查錯誤mysql

sudo systemctl status [pattern]

在我們的例子中,我們想查看 mysql 是否正在運行,因此可以輸入

systemctl status mysql.service

如果服務正在運行,您應該會看到此輸出

systemctl status mysql
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2017-01-10 23:10:06 EST; 1h 3min ago
 Main PID: 1206 (mysqld)
   CGroup: /system.slice/mysql.service
           └─1206 /usr/sbin/mysqld

注意:如果服務已停止運行,您將看到一條短訊息,指示沒有該名稱的服務正在運行,然後跳到步驟 3。

2)mysql使用停止服務systemctl

service注意:[pattern] 必須是或列出的名稱initctl。我使用的原因pattern是因為systemctl使用正規表示式匹配,所以如果必須使用參數,請小心kill

sudo systemctl stop [pattern]

其中pattern代表 mysql 守護程式/服務名稱。如果停止不起作用嘗試

sudo systemctl kill [pattern]

例如

sudo systemctl stop mysql

3) 卸載/清除mysql

如果您需要完全清除,請確保首先停止服務或進程,然後確保刪除正確的檔案和目錄!

注意:確保您的目標mysql版本正確。例如,如果您使用5.5,請適當調整版本號。

警告:以下步驟將刪除您的資料! (必須執行第一條指令才能進行備份)

來源:如何解除安裝MySQL?

tar -zcvf ~/msql_backup.tar.gz /etc/mysql /var/lib/mysql 
sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-5.7 mysql-client-core-5.7
sudo rm -rfv /etc/mysql /var/lib/mysql
sudo apt autoremove
sudo apt autoclean

4) 修復損壞的包並處理缺少的依賴項

如果上述步驟對您不起作用,您可能需要使用修復所造成的損壞的選項apt來運行。--fix-broken

確保apt update先做後做apt install

sudo apt update    
sudo apt install mysql-server mysql-client --fix-broken --fix-missing

5)當一切都失敗時,mysql自己建置和安裝

如果上述方法都不起作用,您將必須手動下載原始程式碼、編譯並使用 make 或 bash 從那裡安裝(不像聽起來那麼痛苦,因為它都是自動化的)。

答案2

第一篇文章的問題是您無法重新配置不適合 sql 專案的元包。您需要指定目前的發布項。

說使用;

apt search mysql-server

那應該會顯示一個包列表,即

“mysql-server-5.7”“mysql-server-core-5.7”或更高版本

然後;

dpkg-reconfigure --force mysql-server-5.7 mysql-server-core-5.7

完畢。

答案3

這是適合您的正確解決方案

首先,您必須刪除 mysql-server 的所有軟體包:

警告:以下步驟將刪除您的資料!先做好備份!

sudo rm -rf /var/lib/mysql

然後安裝:

sudo apt-get install lamp-server^

或者你可以這樣做:

sudo apt-get install mysql-server

答案4

從 MySQL 切換到 MariaDB 時也會發生此錯誤(https://bugs.launchpad.net/ubuntu/+source/mysql-5.7/+bug/1490071)。

MySQL 二進位資料檔與 MariaDB 不相容,所以我切換回 MySQL,因為我沒有時間搞亂 mysqldump。

首先,我必須將 MariaDB 資料從 移走/var/lib/mysql,然後安裝 MySQL,然後將原始資料從/var/lib/mysql-5.7(此備份是在錯誤發生之前自動建立的)移至/var/lib/mysql

相關內容