首頁>Ubuntu>source

最近,我尝試使用Ubuntu 20.04在我的計算機上安裝軟體包mysql-server-8.0.我遇到了一些問题,決定完全卸載並重新安裝mysql。

因此,如果我尝試通過 sudo apt-get remove mysql-server-8.0卸載它 ,我將得到以下輸出:

sudo apt-get remove mysql-server-8.0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-5.4.0-54 linux-headers-5.4.0-54-generic linux-image-5.4.0-54-generic linux-modules-5.4.0-54-generic linux-modules-extra-5.4.0-54-generic mecab-ipadic mecab-ipadic-utf8 mecab-utils python3-imdbpy
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  mysql-server-8.0
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
2 not fully installed or removed.
After this operation, 1465 kB disk space will be freed.
Do you want to continue? [Y/n] y
dpkg: error processing package mysql-server-8.0 (--remove):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting a removal
dpkg: too many errors, stopping
Errors were encountered while processing:
 mysql-server-8.0
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)

輸出建議重新安裝该軟體包,因此我尝試了此操作:

sudo apt install --reinstall mysql-server-8.0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-5.4.0-54 linux-headers-5.4.0-54-generic linux-image-5.4.0-54-generic linux-modules-5.4.0-54-generic linux-modules-extra-5.4.0-54-generic python3-imdbpy
Use 'sudo apt autoremove' to remove them.
Suggested packages:
  mailx tinyca
The following packages will be upgraded:
  mysql-server-8.0
1 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
2 not fully installed or removed.
Need to get 0 B/1261 kB of archives.
After this operation, 1024 B of additional disk space will be used.
Preconfiguring packages ...
(Reading database ... 751683 files and directories currently installed.)
Preparing to unpack .../mysql-server-8.0_8.0.22-0ubuntu0.20.04.3_amd64.deb ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
dpkg: warning: old mysql-server-8.0 package pre-removal script subprocess returned error exit status 1
dpkg: trying script from the new package instead ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
dpkg: error processing archive /var/cache/apt/archives/mysql-server-8.0_8.0.22-0ubuntu0.20.04.3_amd64.deb (--unpack):
 new mysql-server-8.0 package pre-removal script subprocess returned error exit status 1
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
Failed to preset unit: File mysql.service: Link has been severed
/usr/bin/deb-systemd-helper: error: systemctl preset failed on mysql.service: No such file or directory
Failed to start mysql.service: Unit mysql.service not found.
invoke-rc.d: initscript mysql, action "start" failed.
Unit mysql.service could not be found.
dpkg: error while cleaning up:
 installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 /var/cache/apt/archives/mysql-server-8.0_8.0.22-0ubuntu0.20.04.3_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

這裏有趣的部分是這一行:

Failed to stop mysql.service: Unit mysql.service not loaded.

没有正在執行的mysql服務:

systemctl status mysql
Unit mysql.service could not be found.

似乎失败了,因為没有執行mysql服務.我也無法開始。

systemctl start mysql 
Failed to start mysql.service: Unit mysql.service not found.

現在我被困在這裏,無法再次卸載/重新安裝mysql.我還尝試用突觸和 sudo dpkg --purge --force-all mysql-server-8.0删除軟體包 ,這是我在網際網路上找到的.他们都輸出一條訊息,告诉我包裝處於不良狀態。

dpkg -l | egrep -v '^ii|rc' 给出以下輸出:

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
+++-===========================================================-==========================================================-============-======================================================================================================
it  desktop-file-utils                                          0.24+linuxmint1                                            amd64        Utilities for .desktop files
it  gnome-menus                                                 3.36.0-1ubuntu1                                            amd64        GNOME implementation of the freedesktop menu specification
it  hicolor-icon-theme                                          0.17-2                                                     all          default fallback theme for FreeDesktop.org icon themes
it  man-db                                                      2.9.1-1                                                    amd64        tools for reading manual pages
it  mime-support                                                3.64ubuntu1                                                all          MIME files 'mime.types' & 'mailcap', and support programs
pU  mysql-client-8.0                                            8.0.22-0ubuntu0.20.04.3                                    amd64        MySQL database client binaries
pi  mysql-common                                                5.8+1.0.5ubuntu2                                           all          MySQL database common files, e.g. /etc/mysql/my.cnf
rFR mysql-server-8.0                                            8.0.22-0ubuntu0.20.04.2                                    amd64        MySQL database server binaries and system database setup
it  shared-mime-info                                            1.15-1                                                     amd64        FreeDesktop.org shared MIME database and spec
iU  xserver-common                                              2:1.20.8-2ubuntu2.6                                        all          common files used by various X servers
iU  xserver-xephyr                                              2:1.20.8-2ubuntu2.6                                        amd64        nested X server
iU  xserver-xorg-core                                           2:1.20.8-2ubuntu2.6                                        amd64        Xorg X server - core server
iU  xserver-xorg-legacy                                         2:1.20.8-2ubuntu2.6                                        amd64        setuid root Xorg server wrapper
iU  xwayland                                                    2:1.20.8-2ubuntu2.6                                        amd64        Xwayland X server

ls -al /etc/init.d/ | grep mysql 给出:

-rwxr-xr-x   1 root root  5607 Nov  6  2019 mysql
最新回復
  • 6月前
    1 #

    wget -c http://security.ubuntu.com/ubuntu/pool/main/m/mysql-8.0/mysql-server-8.0_8.0.22-0ubuntu0.20.04.3_amd64.deb
    

    直接使用dpkg安裝軟體包。

    sudo dpkg -i mysql-server-8.0_8.0.22-0ubuntu0.20.04.3_amd64.deb
    

    只有在没有錯誤的情况下。

    software-properties-gtk
    

    ,然後選擇从主服務器下載。

    sudo apt update && sudo dpkg --configure -a && sudo apt -f install
    

    然後更新您的系統。

    sudo apt full-upgrade
    

  • 6月前
    2 #

    要删除MySQL,請首先執行以下命令:

    sudo apt remove -y mysql-*
    

    然後:

    sudo apt purge -y mysql-*
    

    現在,安裝 mysql 再次,更新軟體包列表並使用命令

    sudo apt update
    sudo apt install mysql-server
    

  • 6月前
    3 #

    我設法解決了特定的問题,尽管這可能不是解決問题的最干净的方法。 由於删除指令碼由於mysql服務不存在而失败,因此我尝試了以下操作:

    匯航到/ var / lib / dpkg / info /

    打開檔案 mysql-server-8.0-prerm 作為根使用者(例如,使用gedit的使用者),這是删除前的指令碼

    我已對試圖停止该服務的行进行了評論:

    #if [ -x "/etc/init.d/mysql" ]; then #invoke-rc.d mysql stop || exit 1 #fi

    然後我跑了 sudo dpkg --purge --force-all mysql-server-8.0

    這给出了一些警告,但" --force" 開關仍然迫使軟體包卸載

    在删除軟體包後,我現在安裝了一个损壞的軟體包(mysql-client-8.0),可以使用Synaptic軟體包管理器的GUI删除它(apt-get remove也可能起作用)

    這至少對我来說解決了這个問题,我可以再次安裝其他軟體包.即使新軟體包由於狀態不稳定也不需要mysql,也無法安裝。

    非常感谢所有在這裏帮助我的人.很抱歉您浪费了我的時間,但是也许其他人认為您的答案很有帮助!

  • package management:倾向於不从所需来源更新
  • python:ImportError:無法从'distutils'(/usr/lib/python39/distutils/__init__py)匯入名稱'sysconfig'