如何重新安装mysql?


38

软件升级中断了,除其他外,mysql和我还无法恢复它。

可能原因:我的启动磁盘快满了;升级在完成之前就填满了磁盘,因此一切都一团糟。我给了系统更多的磁盘,并将/ var移到了自己的分区。我仍然没有尝试恢复mysql。

以下是到目前为止我尝试过的所有操作(全部都是root用户)。首先,mysql无法启动(443)。尝试修复(444,445)失败。尝试删除mysql和(?)apparmor失败(446、7、8)。尝试更有效地删除mysql似乎成功了(449),并且不再看到以前的错误(450,1,2)。无法重新配置Mysql,因为它不再存在(453),但是尝试重新安装它会返回旧的错误消息,我们回到第一个(454)。

我还检查了这个问题(即使就我而言,由于升级到12.04而没有中断:它已经在12.10上运行了) 在升级到12.04之后修复了损坏的myslq-server软件包, 并尝试了其中的建议(458,461, 462)无济于事。

我该怎么办?

这是在3.5.0-25-通用#39-Ubuntu SMP上进行的2月25日星期一18:26:58 UTC 2013 x86_64 x86_64 x86_64 GNU / Linux

    443  service mysql start
         start: Job failed to start

    444  dpkg-reconfigure mysql-server-5.5
         /usr/sbin/dpkg-reconfigure: mysql-server-5.5
         is broken or not fully installed

    445  apt-get -f install
         ...
         Setting up mysql-server-5.5 (5.5.29-0ubuntu0.12.10.1) ...
         start: Job failed to start
         invoke-rc.d: initscript mysql, action "start" failed.
         dpkg: error processing mysql-server-5.5 (--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.5; however:
         Package mysql-server-5.5 is not configured yet.
         dpkg: error processing 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.5
           mysql-server
         E: Sub-process /usr/bin/dpkg returned an error code (1)

    446  apt-get remove mysql-server
         ...
         Removing mysql-server ...
         Setting up mysql-server-5.5 (5.5.29-0ubuntu0.12.10.1) ...
         start: Job failed to start
         invoke-rc.d: initscript mysql, action "start" failed.
         dpkg: error processing mysql-server-5.5 (--configure):
         subprocess installed post-installation script
         returned error exit status 1
         No apport report written because MaxReports is reached already
         Errors were encountered while processing:
           mysql-server-5.5
         E: Sub-process /usr/bin/dpkg returned an error code (1)


    447  apt-get remove apparmor
         ...
         Package 'apparmor' is not installed, so not removed
         0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
         1 not fully installed or removed.
         After this operation, 0 B of additional disk space will be used. 
         Setting up mysql-server-5.5 (5.5.29-0ubuntu0.12.10.1) ...
         start: Job failed to start
         invoke-rc.d: initscript mysql, action "start" failed.
         dpkg: error processing mysql-server-5.5 (--configure):
         subprocess installed post-installation script
         returned error exit status 1
         Errors were encountered while processing:
           mysql-server-5.5
         E: Sub-process /usr/bin/dpkg returned an error code (1)


    448  apt-get remove mysql-server
         Reading package lists... Done
         Building dependency tree       
         Reading state information... Done
         Package 'mysql-server' is not installed, so not removed
         0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
         1 not fully installed or removed.
         After this operation, 0 B of additional disk space will be used.
         Setting up mysql-server-5.5 (5.5.29-0ubuntu0.12.10.1) ...
         start: Job failed to start
         invoke-rc.d: initscript mysql, action "start" failed.
         dpkg: error processing mysql-server-5.5 (--configure):
         subprocess installed post-installation script
         returned error exit status 1
         Errors were encountered while processing:
           mysql-server-5.5
         E: Sub-process /usr/bin/dpkg returned an error code (1)

    449  dpkg -r mysql-server-5.5
         (Reading database ... 322156 files and directories
         currently installed.)
         Removing mysql-server-5.5 ...
         Processing triggers for man-db ...
         Processing triggers for ureadahead ...

    450  apt-get remove mysql-server
         Reading package lists... Done
         Building dependency tree        
         Reading state information... Done
         Package 'mysql-server' is not installed, so not removed
         0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

    451  apt-get remove apparmor
         Reading package lists... Done
         Building dependency tree       
         Reading state information... Done
         Package 'apparmor' is not installed, so not removed
         0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

    452  apt-get -f install
         Reading package lists... Done
         Building dependency tree       
         Reading state information... Done
         0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

    453  dpkg-reconfigure mysql-server-5.5
         /usr/sbin/dpkg-reconfigure: mysql-server-5.5 is broken
         or not fully installed

    454  apt-get install mysql-server
         Reading package lists... Done
         Building dependency tree       
         Reading state information... Done
         The following extra packages will be installed:
           mysql-server-5.5
         Suggested packages:
           tinyca mailx
         The following NEW packages will be installed:
           mysql-server mysql-server-5.5
         0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
         Need to get 0 B/8,851 kB of archives.
         After this operation, 32.8 MB of additional disk space
         will be used.
         Do you want to continue [Y/n]? 
         Preconfiguring packages ...
         Selecting previously unselected package mysql-server-5.5.
         (Reading database ... 322081 files and directories
         currently installed.)
         Unpacking mysql-server-5.5 (from 
         .../mysql-server-5.5_5.5.29-0ubuntu0.12.10.1_amd64.deb) ...
         Selecting previously unselected package mysql-server.
         Unpacking mysql-server (from 
         .../mysql-server_5.5.29-0ubuntu0.12.10.1_all.deb) ...
         Processing triggers for ureadahead ...
         Processing triggers for man-db ...
         Setting up mysql-server-5.5 (5.5.29-0ubuntu0.12.10.1) ...
         start: Job failed to start
         invoke-rc.d: initscript mysql, action "start" failed.
         dpkg: error processing mysql-server-5.5 (--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.5; however:
         Package mysql-server-5.5 is not configured yet.
         dpkg: error processing 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.5
           mysql-server
         E: Sub-process /usr/bin/dpkg returned an error code (1)


    458  apt-get remove --purge mysql-server
         Reading package lists... Done
         Building dependency tree       
         Reading state information... Done
         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, 116 kB disk space will be freed.
         Do you want to continue [Y/n]? 
         (Reading database ... 322159 files and directories
         currently installed.)
         Removing mysql-server ...
         Setting up mysql-server-5.5 (5.5.29-0ubuntu0.12.10.1) ...
         start: Job failed to start
         invoke-rc.d: initscript mysql, action "start" failed.
         dpkg: error processing mysql-server-5.5 (--configure):
         subprocess installed post-installation script
         returned error exit status 1
         Errors were encountered while processing:
           mysql-server-5.5
         E: Sub-process /usr/bin/dpkg returned an error code (1)

    461  touch /etc/apparmor.d/local/usr.sbin.mysqld
         (no output)

    462  service mysql start
         start: Job failed to start

Answers:


80

首先,删除MySQL:

sudo apt purge mysql-server mysql-client mysql-common
sudo apt autoremove
sudo mv -iv /var/lib/mysql /var/tmp/mysql-backup
sudo rm -rf /var/lib/mysql*

然后重新安装:

sudo apt update
sudo apt install mysql-server
sudo mysql_install_db
sudo /usr/bin/mysql_secure_installation

1
完美的解释!
Postadelmaga 2014年

我认为值得一提的--purge是,它不一定会想要的,因为它也会删除配置文件。特别是在mysql的情况下,我想知道是否还会删除dbs?
user50849 2014年

10
要删除配置和数据库,您将必须删除/etc/mysql/var/lib/mysql
Anne van Rossum 2015年

2
您应该停止mysql服务以删除mysql-server
Viktor

5
2017-05-20 15:12:01 [警告]不建议使用mysql_install_db。请考虑切换到mysqld --initialize
Flaudre '17

12

在Ubuntu 16.04中,针对我的情况进行修复的方法是(请首先备份数据库,数据库将丢失):

sudo apt remove --purge mysql-server mysql-client mysql-common
sudo apt autoremove
sudo mv -iv /var/lib/mysql /var/tmp/mysql-backup
sudo rm -rf /var/lib/mysql*
sudo apt install mysql-server

(以某种方式,我之前的呼叫apt purge mysql-server似乎没有成功。我认为那apt purge foo等同于apt remove --purge foo...)


这将删除所有数据库。如果有任何重要数据,则需要备份。
flickerfly '16

8

我遇到了完全相同的错误,并尝试了您执行的大多数步骤,并获得了相同的结果。以下终于为我工作。

apt-get purge mysql-server mysql-client mysql-common mysql-client-5.5 mysql-server-5.5

之后,mysql安装正常。


1

我不确定对我来说是什么情况,但是其他解决方案均不起作用,但始终出错。我试过了apt-get purge mysql-*,然后autoremoveautoclean。之后安装就可以了。

**

确保备份数据库,以上命令也可能将其删除

**


0

如果你只是跑步

sudo apt-get update
sudo apt-get install mysql-server

它会更新mysql,这解决了我更新到16.04 lts后遇到的问题。

或者只是跑

sudo apt-get install lamp-server^

更新所有服务器软件包。


0

对于MySQL 5.7版本,我按照前面所述删除了MySQL:

sudo apt purge mysql-server mysql-client mysql-common
sudo apt autoremove
sudo rm -rf /var/lib/mysql*

并在帮助下安装它:

sudo apt-get update
sudo apt-get install mysql-server
mysql_secure_installation

要测试是否一切正常:

systemctl status mysql.service

资源


-5

从默认的Ubuntu存储库安装phpMyAdmin。然后运行:

dpkg --configure mysql-server-5.5
apt-get purge mysql-server mysql-client mysql-common mysql-client-5.5 mysql-server-5.5
apt-get autoremove
apt-get autoclean
apt-get update
apt-get install  mysql-server
service mysql restart

5
为什么要安装phpMyAdmin?那完全没有必要。
卢西奥2014年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.