更新 MYSQL 包时出错

更新 MYSQL 包时出错

我的电脑死机了,我忘了它正在后台更新,所以我重启了电脑。重启后我尝试登录(如果我输入了错误的密码,它会提示密码错误),但随后屏幕会空白一秒钟,然后返回到登录屏幕。我启动到恢复模式并运行包恢复管理器。这招奏效了,让我可以重新登录。我运行sudo apt-get updatesudo apt-get install确保所有包都正确更新。但是,mysql 不再工作(我无法打开服务)。当我尝试时,sudo apt-get install 出现以下错误消息:

2 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.43-0ubuntu0.14.04.1) ...
start: Job failed to start
invoke-rc.d: initscript mysql, action "start" failed.
No apport report written because the error message indicates its a followup error from a previous failure.
                          dpkg: error processing package 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 package mysql-server (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 mysql-server-5.5
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

我也尝试过,sudo apt-get -f install但得到了同样的错误消息。我的问题是如何修复这个问题并让数据库重新工作,同时要非常小心,以确保实际的 mysql 数据库/表不会被删除。

更新

按照此回答我删除了 mysql 并重新安装。

sudo apt-get clean

sudo apt-get autoclean

sudo apt-get remove --purge mysql-client-5.5 mysql-client-core-5.5 mysql-common mysql-server mysql-server-5.5 mysql-server-core-5.5

sudo apt-get install mysql-server

最后一步没有成功(安装成功,但在安装结束时显示 root 密码已设置,数据库无法启动)。我没有在终端中执行最后一步,而是使用 webmin install mysql(这是我最初设置数据库的方式),数据库可以正常启动和停止。只是我的数据库目录位置位于第二个硬盘上/media/D/mysql/,而不是,并且正常工作的只是一组更旧的文件,当我将它们复制到第二个硬盘时,/var/lib/mysql它们从未被删除。/var/lib/mysql

遵循这些指示,我最初用它来更改目录,我编辑了相关的配置文件(显然我没有将文件复制到 D 盘,因为它们已经在那里了,我只是编辑了配置文件)。更改数据库目录位置后,数据库将不再启动。

以下是错误日志中的内容(终端只是告诉您它无法启动):

50514 16:50:55 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist
150514 16:50:55 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
150514 16:50:55 InnoDB: The InnoDB memory heap is disabled
150514 16:50:55 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150514 16:50:55 InnoDB: Compressed tables use zlib 1.2.8
150514 16:50:55 InnoDB: Using Linux native AIO
150514 16:50:55 InnoDB: Initializing buffer pool, size = 128.0M
150514 16:50:55 InnoDB: Completed initialization of buffer pool
150514 16:50:55 InnoDB: highest supported file format is Barracuda.
150514 16:50:55  InnoDB: Waiting for the background threads to start
150514 16:50:56 InnoDB: 5.5.43 started; log sequence number 1595675
150514 16:50:56 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
150514 16:50:56 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
150514 16:50:56 [Note] Server socket created on IP: '127.0.0.1'.
150514 16:50:56 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

我研究了这个错误Table 'mysql.host' doesn't exist ,发现了这个回答,我试图确保 mysql 具有权限(见下文),但没有用。

chown -R mysql /media/D/mysql
chgrp -R mysql /media/D/mysql

一个建议是查看的输出mysqld,它在终端中产生以下错误:

150514 17:00:55 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
150514 17:00:55 [Note] mysqld (mysqld 5.5.43-0ubuntu0.14.04.1) starting as process 11565 ...
150514 17:00:55 [Warning] Can't create test file /media/D/mysql/computername.lower-test
150514 17:00:55 [Warning] Can't create test file /media/D/mysql/computername.lower-test
mysqld: Can't change dir to '/media/D/mysql/' (Errcode: 13)
150514 17:00:55 [ERROR] Aborting

150514 17:00:55 [Note] mysqld: Shutdown complete

更新 2

我更改了 mysql 配置 /etc/mysql/my.cnf,它现在可以正确使用 key_buffer_size,并且mysqld可以正常启动。sudo mysql start但是,会出现以下错误:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

解决了

太蠢了!文件的实际位置是 /media/D_/mysql,而不是 /media/D/mysql。然后当我弄清楚了这一点时,我还必须记住在 AppArmor 配置文件中进行更改。如果错误消息说目录不存在,那就简单多了!!!!

答案1

确保您my.cnf没有任何已弃用的选项。我遇到了类似的问题,因为我已default-character-set在 下列出[mysqld],但在较新版本的 mysql 中,它已重命名为character_set_server。但是,mysql 非常无助地让我知道这一点,只是在尝试启动服务时挂起。并且包管理器通常会在安装新版本时尝试停止和/或启动服务。

要检查,请尝试mysqld自行运行。如果存在配置问题,它应该会提示问题并立即停止运行。

相关内容