
我正在嘗試在 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 remove
MySQL 並重新安裝,這留下了錯誤的資料檔案和配置,因此下一次安裝會發現它並以相同的方式失敗。
顯然,即使是後續也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 資料。僅在全新安裝時或在您了解後果的情況下執行此操作。