MySQL 安装因错误而中止

MySQL 安装因错误而中止

我正在尝试在 Raspbian Jessie 上安装 MySQL。这在另一台具有相同设置的机器上运行顺利;然而,在第二个,我无法让它工作。

在包配置期间,系统提示我输入密码,经过一段时间的等待后,我得到:

┌─────────────────────────────────────┤ Configuring mysql-server-5.5 ├──────────────────────────────────────┐    
│                                                                                                           │    
│ Unable to set password for the MySQL "root" user                                                          │    
│                                                                                                           │    
│ An error occurred while setting the password for the MySQL administrative user. This may have happened    │    
│ because the account already has a password, or because of a communication problem with the MySQL server.  │    
│                                                                                                           │    
│ You should check the account's password after the package installation.                                   │    
│                                                                                                           │    
│ Please read the /usr/share/doc/mysql-server-5.5/README.Debian file for more information.                  │    
│                                                                                                           │    
│                                                  <Ok>                                                     │    
│                                                                                                           │    
└───────────────────────────────────────────────────────────────────────────────────────────────────────────┘    

深入挖掘后,我发现这个错误是由于MySQL无法启动引起的。我检查了/var/log/mysql/error.log,其中包含以下条目:

161217 23:33:16 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
161217 23:33:16 [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.
161217 23:33:17 [Note] /usr/sbin/mysqld (mysqld 5.5.53-0+deb8u1) starting as process 16476 ...
161217 23:33:17 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
161217 23:33:17 [Note] Plugin 'FEDERATED' is disabled.
161217 23:33:17 InnoDB: The InnoDB memory heap is disabled
161217 23:33:17 InnoDB: Mutexes and rw_locks use GCC atomic builtins
161217 23:33:17 InnoDB: Compressed tables use zlib 1.2.8
161217 23:33:17 InnoDB: Using Linux native AIO
161217 23:33:17 InnoDB: Initializing buffer pool, size = 128.0M
161217 23:33:17 InnoDB: Completed initialization of buffer pool
InnoDB: Error: auto-extending data file ./ibdata1 is of a different size
InnoDB: 0 pages (rounded down to MB) than specified in the .cnf file:
InnoDB: initial 640 pages, max 0 (relevant if non-zero) pages!
161217 23:33:17 InnoDB: Could not open or create data files.
161217 23:33:17 InnoDB: If you tried to add new data files, and it failed here,
161217 23:33:17 InnoDB: you should now edit innodb_data_file_path in my.cnf back
161217 23:33:17 InnoDB: to what it was, and remove the new ibdata files InnoDB created
161217 23:33:17 InnoDB: in this failed attempt. InnoDB only wrote those files full of
161217 23:33:17 InnoDB: zeros, but did not yet use them in any way. But be careful: do not
161217 23:33:17 InnoDB: remove old data files which contain your precious data!
161217 23:33:17 [ERROR] Plugin 'InnoDB' init function returned error.
161217 23:33:17 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
161217 23:33:17 [ERROR] Unknown/unsupported storage engine: InnoDB
161217 23:33:17 [ERROR] Aborting

161217 23:33:17 [Note] /usr/sbin/mysqld: Shutdown complete

161217 23:33:18 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

这不是升级,而是全新安装(除了我尝试安装 MySQL 几次,mysql-server-5.5在尝试之间进行清除之外)。

不过,我应该提到的是,我在第一次尝试时就耗尽了存储空间(根分区不足 2 GB)。我尝试通过用 16 GB 卡替换 2 GB SD 卡、dd将旧卡的内容复制到新卡并扩展分区来解决此问题。我仍然无法让它工作,而第一个系统(从一开始就有 4 GB 卡)工作得很好。这里有什么问题,我该如何解决它?

答案1

显然,该问题是由于第一次尝试时存储空间不足引起的:MySQL 尝试创建一个数据文件,但由于空间不足而失败,并留下了损坏的数据文件以及指向它的配置文件。

IIRC 我的第一次尝试是sudo apt-get removeMySQL 并重新安装,这留下了错误的数据文件和配置,因此下一次安装会发现它并以同样的方式失败。

显然,即使是后续也sudo apt-get purge mysql-server-5.5没有删除这些项目。以下命令序列最终对我起到了作用:

sudo apt-get purge mysql-server-5.5
sudo rm -R /etc/mysql
sudo rm -R /var/lib/mysql
sudo apt-get install mysql-server

之后MySQL就出现了,我可以登录MySQL控制台了。

重要提示:这将永久删除系统上的所有 MySQL 数据。仅在全新安装时或在您了解后果的情况下执行此操作。

相关内容