2017年2月26日 星期日

在樹莓派上安裝 R 語言

自從去年對 R 語言產生興趣後, 就一直想找時間好好來學習測試. 但想學的東西實在太多了, 時間總是不夠用. 最近聽了兩場機器學習的演講後, 對 R 語言又熱衷起來. 在資料探勘與機器學習這兩個領域上, Python 與 R 語言的使用度非常高, 我非常看好這兩個語言的發展. 參考資料探勘專業網站 KDnuggets 2014~2015 調查結果, R 與 Python 獨占鰲頭, 分別為 51% 與 29%, 合計占 80%, 且持續上升中, 其他語言則逐漸萎縮 :


今天在 "R語言 : 數學計算、統計模型與金融實務分析應用" 這本書上看到 R 語言也可以安裝在 Linux 機器上, 我想應該可以在樹莓派上跑吧! 下午回到鄉下後, 便將 B+ 那塊板子的 SD 卡先做備份, 然後用下列指令進行安裝 :

首先更新軟體套件清單 (這步驟最好先做, 否則可能在安裝過程發現找不到某些相依套件) :

$ sudo apt-get update
然後安裝 R 軟體 :

$ sudo apt-get install r-base

pi@raspberrypi:~ $ sudo apt-get install r-base
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libasn1-8-heimdal libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal libhx509-5-heimdal
  libkrb5-26-heimdal libroken18-heimdal libwind0-heimdal libxfce4ui-1-0 xfce-keyboard-shortcuts
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  autotools-dev bzip2-doc cdbs gfortran gfortran-4.9 libblas-dev libbz2-dev libgfortran-4.9-dev libjpeg-dev libjpeg62-turbo-dev
  liblapack-dev liblzma-dev libncurses5-dev libpaper-utils libpaper1 libpcre3-dev libpcrecpp0 libreadline-dev libreadline6-dev
  libtinfo-dev r-base-core r-base-dev r-base-html r-cran-boot r-cran-class r-cran-cluster r-cran-codetools r-cran-foreign
  r-cran-kernsmooth r-cran-lattice r-cran-mass r-cran-matrix r-cran-mgcv r-cran-nlme r-cran-nnet r-cran-rpart r-cran-spatial
  r-cran-survival r-doc-html r-recommended zip
Suggested packages:
  devscripts gfortran-doc gfortran-4.9-doc libgfortran3-dbg liblzma-doc ncurses-doc readline-doc ess r-doc-info r-doc-pdf r-mathlib
  debhelper texlive-base texlive-latex-base texlive-generic-recommended texlive-fonts-recommended texlive-fonts-extra
  texlive-extra-utils texlive-latex-recommended texlive-latex-extra texinfo
The following NEW packages will be installed:
  autotools-dev bzip2-doc cdbs gfortran gfortran-4.9 libblas-dev libbz2-dev libgfortran-4.9-dev libjpeg-dev libjpeg62-turbo-dev
  liblapack-dev liblzma-dev libncurses5-dev libpaper-utils libpaper1 libpcre3-dev libpcrecpp0 libreadline-dev libreadline6-dev
  libtinfo-dev r-base r-base-core r-base-dev r-base-html r-cran-boot r-cran-class r-cran-cluster r-cran-codetools r-cran-foreign
  r-cran-kernsmooth r-cran-lattice r-cran-mass r-cran-matrix r-cran-mgcv r-cran-nlme r-cran-nnet r-cran-rpart r-cran-spatial
  r-cran-survival r-doc-html r-recommended zip
0 upgraded, 42 newly installed, 0 to remove and 17 not upgraded.
Need to get 44.0 MB of archives.
After this operation, 84.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main libpaper1 armhf 1.1.24+nmu4 [21.4 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main libpcrecpp0 armhf 2:8.35-3.3+deb8u4 [140 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main autotools-dev all 20140911.1 [70.5 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ jessie/main bzip2-doc all 1.0.6-7 [307 kB]
Get:5 http://mirrordirector.raspbian.org/raspbian/ jessie/main gfortran armhf 4:4.9.2-2 [1,294 B]
Get:6 http://mirrordirector.raspbian.org/raspbian/ jessie/main cdbs all 0.4.130+deb8u1 [77.1 kB]
Get:7 http://mirrordirector.raspbian.org/raspbian/ jessie/main libgfortran-4.9-dev armhf 4.9.2-10 [179 kB]
Get:8 http://mirrordirector.raspbian.org/raspbian/ jessie/main gfortran-4.9 armhf 4.9.2-10 [4,525 kB]
Get:9 http://mirrordirector.raspbian.org/raspbian/ jessie/main libreadline-dev armhf 6.3-8 [994 B]
Get:10 http://mirrordirector.raspbian.org/raspbian/ jessie/main libblas-dev armhf 1.2.20110419-10 [117 kB]
Get:11 http://mirrordirector.raspbian.org/raspbian/ jessie/main libbz2-dev armhf 1.0.6-7 [27.5 kB]
Get:12 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjpeg62-turbo-dev armhf 1:1.3.1-12 [400 kB]
Get:13 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjpeg-dev all 1:1.3.1-12 [49.3 kB]
Get:14 http://mirrordirector.raspbian.org/raspbian/ jessie/main liblapack-dev armhf 3.5.0-4 [1,364 kB]
Get:15 http://mirrordirector.raspbian.org/raspbian/ jessie/main liblzma-dev armhf 5.1.1alpha+20120614-2 [272 kB]
Get:16 http://mirrordirector.raspbian.org/raspbian/ jessie/main libtinfo-dev armhf 5.9+20140913-1 [65.4 kB]
Get:17 http://mirrordirector.raspbian.org/raspbian/ jessie/main libncurses5-dev armhf 5.9+20140913-1 [154 kB]
Get:18 http://mirrordirector.raspbian.org/raspbian/ jessie/main libpaper-utils armhf 1.1.24+nmu4 [17.2 kB]
Get:19 http://mirrordirector.raspbian.org/raspbian/ jessie/main libpcre3-dev armhf 2:8.35-3.3+deb8u4 [413 kB]
Get:20 http://mirrordirector.raspbian.org/raspbian/ jessie/main libreadline6-dev armhf 6.3-8 [105 kB]
Get:21 http://mirrordirector.raspbian.org/raspbian/ jessie/main zip armhf 3.0-8 [326 kB]
Get:22 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-base-core armhf 3.1.1-1 [19.5 MB]
Get:23 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-boot all 1.3-13-1 [571 kB]
Get:24 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-cluster armhf 1.15.3-1 [469 kB]
Get:25 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-foreign armhf 0.8.61-1 [203 kB]
Get:26 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-mass armhf 7.3-34-1 [1,011 kB]
Get:27 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-kernsmooth armhf 2.23-13-1 [80.0 kB]
Get:28 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-lattice armhf 0.20-29-1 [712 kB]
Get:29 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-nlme armhf 3.1.117-1 [1,986 kB]
Get:30 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-matrix armhf 1.1-4-1 [2,851 kB]
Get:31 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-mgcv armhf 1.8-3-1 [1,701 kB]
Get:32 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-survival armhf 2.37-7-1 [4,428 kB]
Get:33 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-rpart armhf 4.1-8-1 [854 kB]
Get:34 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-class armhf 7.3-11-1 [80.4 kB]
Get:35 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-nnet armhf 7.3-8-1 [93.4 kB]
Get:36 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-spatial armhf 7.3-8-1 [115 kB]
Get:37 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-cran-codetools all 0.2-9-1 [45.7 kB]
Get:38 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-recommended all 3.1.1-1 [2,852 B]
Get:39 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-base all 3.1.1-1 [37.5 kB]
Get:40 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-base-dev all 3.1.1-1 [4,018 B]
Get:41 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-doc-html all 3.1.1-1 [529 kB]
Get:42 http://mirrordirector.raspbian.org/raspbian/ jessie/main r-base-html all 3.1.1-1 [81.1 kB]
Fetched 44.0 MB in 7min 7s (103 kB/s)
Extracting templates from packages: 100%
Preconfiguring packages ...
Selecting previously unselected package libpaper1:armhf.
(Reading database ... 131823 files and directories currently installed.)
Preparing to unpack .../libpaper1_1.1.24+nmu4_armhf.deb ...
Unpacking libpaper1:armhf (1.1.24+nmu4) ...
Selecting previously unselected package libpcrecpp0:armhf.
Preparing to unpack .../libpcrecpp0_2%3a8.35-3.3+deb8u4_armhf.deb ...
Unpacking libpcrecpp0:armhf (2:8.35-3.3+deb8u4) ...
Selecting previously unselected package autotools-dev.
Preparing to unpack .../autotools-dev_20140911.1_all.deb ...
Unpacking autotools-dev (20140911.1) ...
Selecting previously unselected package bzip2-doc.
Preparing to unpack .../bzip2-doc_1.0.6-7_all.deb ...
Unpacking bzip2-doc (1.0.6-7) ...
Selecting previously unselected package cdbs.
Preparing to unpack .../cdbs_0.4.130+deb8u1_all.deb ...
Unpacking cdbs (0.4.130+deb8u1) ...
Selecting previously unselected package libgfortran-4.9-dev:armhf.
Preparing to unpack .../libgfortran-4.9-dev_4.9.2-10_armhf.deb ...
Unpacking libgfortran-4.9-dev:armhf (4.9.2-10) ...
Selecting previously unselected package gfortran-4.9.
Preparing to unpack .../gfortran-4.9_4.9.2-10_armhf.deb ...
Unpacking gfortran-4.9 (4.9.2-10) ...
Selecting previously unselected package gfortran.
Preparing to unpack .../gfortran_4%3a4.9.2-2_armhf.deb ...
Unpacking gfortran (4:4.9.2-2) ...
Selecting previously unselected package libblas-dev.
Preparing to unpack .../libblas-dev_1.2.20110419-10_armhf.deb ...
Unpacking libblas-dev (1.2.20110419-10) ...
Selecting previously unselected package libbz2-dev:armhf.
Preparing to unpack .../libbz2-dev_1.0.6-7_armhf.deb ...
Unpacking libbz2-dev:armhf (1.0.6-7) ...
Selecting previously unselected package libjpeg62-turbo-dev:armhf.
Preparing to unpack .../libjpeg62-turbo-dev_1%3a1.3.1-12_armhf.deb ...
Unpacking libjpeg62-turbo-dev:armhf (1:1.3.1-12) ...
Selecting previously unselected package libjpeg-dev.
Preparing to unpack .../libjpeg-dev_1%3a1.3.1-12_all.deb ...
Unpacking libjpeg-dev (1:1.3.1-12) ...
Selecting previously unselected package liblapack-dev.
Preparing to unpack .../liblapack-dev_3.5.0-4_armhf.deb ...
Unpacking liblapack-dev (3.5.0-4) ...
Selecting previously unselected package liblzma-dev:armhf.
Preparing to unpack .../liblzma-dev_5.1.1alpha+20120614-2_armhf.deb ...
Unpacking liblzma-dev:armhf (5.1.1alpha+20120614-2) ...
Selecting previously unselected package libtinfo-dev:armhf.
Preparing to unpack .../libtinfo-dev_5.9+20140913-1_armhf.deb ...
Unpacking libtinfo-dev:armhf (5.9+20140913-1) ...
Selecting previously unselected package libncurses5-dev:armhf.
Preparing to unpack .../libncurses5-dev_5.9+20140913-1_armhf.deb ...
Unpacking libncurses5-dev:armhf (5.9+20140913-1) ...
Selecting previously unselected package libpaper-utils.
Preparing to unpack .../libpaper-utils_1.1.24+nmu4_armhf.deb ...
Unpacking libpaper-utils (1.1.24+nmu4) ...
Selecting previously unselected package libpcre3-dev:armhf.
Preparing to unpack .../libpcre3-dev_2%3a8.35-3.3+deb8u4_armhf.deb ...
Unpacking libpcre3-dev:armhf (2:8.35-3.3+deb8u4) ...
Selecting previously unselected package libreadline6-dev:armhf.
Preparing to unpack .../libreadline6-dev_6.3-8_armhf.deb ...
Unpacking libreadline6-dev:armhf (6.3-8) ...
Selecting previously unselected package libreadline-dev:armhf.
Preparing to unpack .../libreadline-dev_6.3-8_armhf.deb ...
Unpacking libreadline-dev:armhf (6.3-8) ...
Selecting previously unselected package zip.
Preparing to unpack .../archives/zip_3.0-8_armhf.deb ...
Unpacking zip (3.0-8) ...
Selecting previously unselected package r-base-core.
Preparing to unpack .../r-base-core_3.1.1-1_armhf.deb ...
Unpacking r-base-core (3.1.1-1) ...
Selecting previously unselected package r-cran-boot.
Preparing to unpack .../r-cran-boot_1.3-13-1_all.deb ...
Unpacking r-cran-boot (1.3-13-1) ...
Selecting previously unselected package r-cran-cluster.
Preparing to unpack .../r-cran-cluster_1.15.3-1_armhf.deb ...
Unpacking r-cran-cluster (1.15.3-1) ...
Selecting previously unselected package r-cran-foreign.
Preparing to unpack .../r-cran-foreign_0.8.61-1_armhf.deb ...
Unpacking r-cran-foreign (0.8.61-1) ...
Selecting previously unselected package r-cran-mass.
Preparing to unpack .../r-cran-mass_7.3-34-1_armhf.deb ...
Unpacking r-cran-mass (7.3-34-1) ...
Selecting previously unselected package r-cran-kernsmooth.
Preparing to unpack .../r-cran-kernsmooth_2.23-13-1_armhf.deb ...
Unpacking r-cran-kernsmooth (2.23-13-1) ...
Selecting previously unselected package r-cran-lattice.
Preparing to unpack .../r-cran-lattice_0.20-29-1_armhf.deb ...
Unpacking r-cran-lattice (0.20-29-1) ...
Selecting previously unselected package r-cran-nlme.
Preparing to unpack .../r-cran-nlme_3.1.117-1_armhf.deb ...
Unpacking r-cran-nlme (3.1.117-1) ...
Selecting previously unselected package r-cran-matrix.
Preparing to unpack .../r-cran-matrix_1.1-4-1_armhf.deb ...
Unpacking r-cran-matrix (1.1-4-1) ...
Selecting previously unselected package r-cran-mgcv.
Preparing to unpack .../r-cran-mgcv_1.8-3-1_armhf.deb ...
Unpacking r-cran-mgcv (1.8-3-1) ...
Selecting previously unselected package r-cran-survival.
Preparing to unpack .../r-cran-survival_2.37-7-1_armhf.deb ...
Unpacking r-cran-survival (2.37-7-1) ...
Selecting previously unselected package r-cran-rpart.
Preparing to unpack .../r-cran-rpart_4.1-8-1_armhf.deb ...
Unpacking r-cran-rpart (4.1-8-1) ...
Selecting previously unselected package r-cran-class.
Preparing to unpack .../r-cran-class_7.3-11-1_armhf.deb ...
Unpacking r-cran-class (7.3-11-1) ...
Selecting previously unselected package r-cran-nnet.
Preparing to unpack .../r-cran-nnet_7.3-8-1_armhf.deb ...
Unpacking r-cran-nnet (7.3-8-1) ...
Selecting previously unselected package r-cran-spatial.
Preparing to unpack .../r-cran-spatial_7.3-8-1_armhf.deb ...
Unpacking r-cran-spatial (7.3-8-1) ...
Selecting previously unselected package r-cran-codetools.
Preparing to unpack .../r-cran-codetools_0.2-9-1_all.deb ...
Unpacking r-cran-codetools (0.2-9-1) ...
Selecting previously unselected package r-recommended.
Preparing to unpack .../r-recommended_3.1.1-1_all.deb ...
Unpacking r-recommended (3.1.1-1) ...
Selecting previously unselected package r-base.
Preparing to unpack .../r-base_3.1.1-1_all.deb ...
Unpacking r-base (3.1.1-1) ...
Selecting previously unselected package r-base-dev.
Preparing to unpack .../r-base-dev_3.1.1-1_all.deb ...
Unpacking r-base-dev (3.1.1-1) ...
Selecting previously unselected package r-doc-html.
Preparing to unpack .../r-doc-html_3.1.1-1_all.deb ...
Unpacking r-doc-html (3.1.1-1) ...
Selecting previously unselected package r-base-html.
Preparing to unpack .../r-base-html_3.1.1-1_all.deb ...
Unpacking r-base-html (3.1.1-1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for install-info (5.2.0.dfsg.1-6) ...
Processing triggers for hicolor-icon-theme (0.13-1) ...
Processing triggers for gnome-menus (3.13.3-6) ...
Processing triggers for desktop-file-utils (0.22-1) ...
Processing triggers for mime-support (3.58) ...
Setting up libpaper1:armhf (1.1.24+nmu4) ...

Creating config file /etc/papersize with new version
Setting up libpcrecpp0:armhf (2:8.35-3.3+deb8u4) ...
Setting up autotools-dev (20140911.1) ...
Setting up bzip2-doc (1.0.6-7) ...
Setting up cdbs (0.4.130+deb8u1) ...
Setting up libgfortran-4.9-dev:armhf (4.9.2-10) ...
Setting up gfortran-4.9 (4.9.2-10) ...
Setting up gfortran (4:4.9.2-2) ...
update-alternatives: using /usr/bin/gfortran to provide /usr/bin/f95 (f95) in auto mode
update-alternatives: using /usr/bin/gfortran to provide /usr/bin/f77 (f77) in auto mode
Setting up libblas-dev (1.2.20110419-10) ...
update-alternatives: using /usr/lib/libblas/libblas.so to provide /usr/lib/libblas.so (libblas.so) in auto mode
Setting up libbz2-dev:armhf (1.0.6-7) ...
Setting up libjpeg62-turbo-dev:armhf (1:1.3.1-12) ...
Setting up libjpeg-dev (1:1.3.1-12) ...
Setting up liblapack-dev (3.5.0-4) ...
update-alternatives: using /usr/lib/lapack/liblapack.so to provide /usr/lib/liblapack.so (liblapack.so) in auto mode
Setting up liblzma-dev:armhf (5.1.1alpha+20120614-2) ...
Setting up libtinfo-dev:armhf (5.9+20140913-1) ...
Setting up libncurses5-dev:armhf (5.9+20140913-1) ...
Setting up libpaper-utils (1.1.24+nmu4) ...
Setting up libpcre3-dev:armhf (2:8.35-3.3+deb8u4) ...
Setting up libreadline6-dev:armhf (6.3-8) ...
Setting up libreadline-dev:armhf (6.3-8) ...
Setting up zip (3.0-8) ...
Setting up r-base-core (3.1.1-1) ...

Creating config file /etc/R/Renviron with new version
Setting up r-cran-boot (1.3-13-1) ...
Setting up r-cran-cluster (1.15.3-1) ...
Setting up r-cran-foreign (0.8.61-1) ...
Setting up r-cran-mass (7.3-34-1) ...
Setting up r-cran-kernsmooth (2.23-13-1) ...
Setting up r-cran-lattice (0.20-29-1) ...
Setting up r-cran-nlme (3.1.117-1) ...
Setting up r-cran-matrix (1.1-4-1) ...
Setting up r-cran-mgcv (1.8-3-1) ...
Setting up r-cran-survival (2.37-7-1) ...
Setting up r-cran-rpart (4.1-8-1) ...
Setting up r-cran-class (7.3-11-1) ...
Setting up r-cran-nnet (7.3-8-1) ...
Setting up r-cran-spatial (7.3-8-1) ...
Setting up r-cran-codetools (0.2-9-1) ...
Setting up r-recommended (3.1.1-1) ...
Setting up r-base (3.1.1-1) ...
Setting up r-base-dev (3.1.1-1) ...
Setting up r-doc-html (3.1.1-1) ...
Setting up r-base-html (3.1.1-1) ...
Processing triggers for libc-bin (2.19-18+deb8u7) ...

安裝完畢後用 R (注意是大寫) 即可進入 R 語言命令列, 要跳出  R 回到 Linux 的話則輸入 q() :

pi@raspberrypi:~ $ R

R version 3.1.1 (2014-07-10) -- "Sock it to Me"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: arm-unknown-linux-gnueabihf (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> 1+2
[1] 3
> 1/2
[1] 0.5
> q()
Save workspace image? [y/n/c]: n
pi@raspberrypi:~ $

可見樹莓派支援的是 R 3.1.1 版, 沒想到 R 語言在樹莓派也跑得挺順的, 如果寫個 R Script 放在 Crontab 裡面執行, 不就可以自動進行統計分析與機器學習了嗎? 樹莓派作為一個低功耗可 24 小時開機的 Linux 伺服器, 有了 R 語言可說如虎添翼啊!

大部分的 R 操作可在命令列執行, 但若執行 plot() 等繪圖函數時就必須在 X Window 桌面系統的 Terminal 視窗下才會顯示 (例如透過 VNC 進行遠端桌面存取), 如果是透過 Putty 連線, 則執行 plot() 之後不會顯示圖形.



參考 :

Using R with the Pi
R on the Raspberry Pi

樹莓派重新安裝 Raspbian 作業系統

由於最早買的那塊樹莓派 (Type B) 裡的 MySQL 伺服器前幾天莫名其妙無法啟動, 造成 PHP 爬蟲程式無法運作, 在努力搶修兩天後, 因為對 Linux 系統的瞭解實在太膚淺, 無奈只好宣告放棄, 參見 :

# 樹莓派 MySQL/phpMyAdmin 無法登入問題

最後決定還是將 SD 卡格式化, 重新安裝系統算了. 當然在此之前要先將 PHP 專案全部用 WinSCP 複製到 Windows 下保存, 還有 ssmtp.conf 設定檔也複製到 /home/pi 下, 而 Crontab 內容必須用 nano 開啟後複製到 PC 下的記事本中儲存.

$ sudo cp /etc/ssmtp/ssmtp.conf ssmtp.conf

然後將樹莓派關機, 取下 SD 卡放入讀卡機連接 PC 後, 用 SD formatter 程式進行格式化 :


參考 :

記憶卡格式化/抹除工具 : SD Formatter 4.0

再到樹莓派官網下載最新的 Raspbian 作業系統 zip 檔, 目前是 Rasbian Jessie with Pixel (約 1.5GB), 由於官網頻寬較小, 所以要 2 小時才能完成下載 :



下載完成後解開 zip 得到約 4.3GB 的映像檔 2017-01-11-raspbian-jessie.img, 使用 Win32 Disk Imager (或下載免安裝版 Win32DiskImager-0.9.5-binary.zip) 將此映像檔燒入 SD 卡內 (注意, Device 要選對) :




作業系統燒錄完成後將 SD 卡插回樹莓派, 由於新系統無法使用無頭存取方式 (Headless), 因此必須接 HDMI 到螢幕或電視機, 並且插上無線鍵盤滑鼠組的 USB 接收器後再開機. 由於 Raspbian 預設都是英國 UK 使用者觀點 (keyboard, locale, language, timezone, ...), 因此開機登入 (預設帳號 pi, 密碼 raspberry) 後要先用 raspi-config 指令去更改設定, 否則光是鍵盤配置不同就會讓輸入的字元與期望不同 (例如雙引號在英式鍵盤被解讀為 @).

$ sudo raspi-config

這個設定畫面使用上下箭頭移動高亮度項目, 按 Enter 確認或進入選項, 多選時用 Space 鍵選取, 按 Tab 鍵可在不同按鈕間切換 :


首先第一項是擴充檔案系統 (Expand File System), 由於 Raspbian 映像檔大小為 4.3GB, 燒錄到我使用的 8GB 後, 超出 4.3GB 的部分將存取不到, 執行這項功能目的是讓 Raspbian 的 root partition 能擴充至整張 SD 卡, 不致浪費 4.3GB 以外的空間.

第二項 Change User Password 更改使用者密碼, 預設帳號 pi 的密碼是 raspberry, 為了安全最好改掉, 在舊版時我為了方便改成與帳號 pi 相同, 但在 2017 新版 Raspbian 不讓我這樣改了, 太簡單的不會被接受. 執行這項設定時會跳回命令列, 輸入新密碼並確認後會再回到設定畫面.

第三項 Boot Options 是選擇開機時要進入命令列 CML 或桌面 Desktop, 建議是進入命令列 (都選 B1), 因為桌面較占資源. 我的樹莓派主要是用作 IoT 與 cURL 的伺服器, 所以幾乎都是在命令列操作, 不需要的軟體不安裝, 不需要的軟體不執行, 以節省運算資源.



第四項 Internationalization Options 是區域設定, 其中 I1 是設定語系, 為單純起見, 我只用美式英文, 移動上下鍵至 en_US.UTF-8 UTF-8 時按 Space 鍵選取, 這時前面出現 * 表示已被選取 (再按一次 Space 則取消選取). 可以多選, 例如要加入繁體中文就選 lzh_TW UTF-8 這項, 但我覺得用不到所以不選. 參考 :

樹莓派系統設定 : 區域設置 (Locale)




I2 (Change Timezone) 用來設定時區, 選取 Asia/Taipei :



I3 (Change Keyboard Layout) 是設定鍵盤樣式, Keyboard Model 選 Generic 105-key (Intl) PC, Keyboard Layout 選 English (US); Key to function as AltGr 選 The default for the keyboard layout; Compose key 選 No compose key; 而 Use Control+Alt+Backspace to terminate the x server 則選 No.

I4 (Change WiFi Country) 選擇 Taiwan.

第五項 Enable Camera 選 Yes, 因為我已經買了 PiCam 準備要測試.

第六項超頻不要用跳過.

最後一項 Advanced Options 中目前只要打開 SSH 以便遠端 headless 存取即可.


注意, 2017 版 Raspbian 已經內建 VNC Server, 不須再安裝了. 如果需要用到遠端介面, 只要在系統設定中開啟 VNC 功能, 然後在命令列輸入 vncserver 啟動伺服器即可在 PC 上用 VNC Viewer 遠端存取樹莓派桌面了 (最好要用到時再啟動 VNC 伺服器, 不要開機自動啟動, 免得占用資源).

pi@raspberrypi:~ $ vncserver
VNC(R) Server 5.3.2 (RasPi) (r22607) ARMv6 (Oct 4 2016 11:26:16)
Copyright (C) 2002-2016 RealVNC Ltd.
RealVNC and VNC are trademarks of RealVNC Ltd and are protected by trademark
registrations and/or pending trademark applications in the European Union,
United States of America and other jurisdictions.
Protected by UK patent 2481870; US patent 8760366.
See http://www.realvnc.com for information on VNC.
For third party acknowledgements see:
http://www.realvnc.com/products/vnc/documentation/5.3/acknowledgements.txt

If a desktop environment fails to load for this virtual desktop, please see:
 http://www.realvnc.com/doclink/kb-345?version=5.3.2.22607
Running applications in /etc/vnc/xstartup

VNC Server catchphrase: "Bazaar baboon baker. Athena denial Berlin."
             signature: 53-d4-2f-81-aa-24-bc-0a

Log file is /home/pi/.vnc/raspberrypi:1.log
New desktop is raspberrypi:1 (192.168.2.111:1)   ==> 注意是編號 1 桌面

在遠端 PC 的 VNC Viewer 連線時要注意是第幾個桌面, 這裡是桌面 1 :



VNC Server 預設帳號是 pi, 預設密碼為 raspberry, 可用 vncpasswd 指令修改 (我改成跟樹莓派登入帳密相同) :

pi@raspberrypi:~ $ sudo vncpasswd -print
Password:
Verify:
Password=f602f71dcfdd782a

參考 :

# 以 VNC 和 Raspberry Pi 連線

以上便是 2017 版 Raspbian 的主要系統設定.

接下來是安裝一定會用到的基本軟體 :
  1. zip 與 unzip
  2. Apache+PHP+MySQL 伺服器
  3. PHP cURL
  4. ssmtp 與 mailutils
首先是壓縮解壓縮軟體 zip 與 unzip :

sudo apt-get install zip unzip

pi@raspberrypi:~ $ sudo apt-get install zip unzip
Reading package lists... Done
Building dependency tree
Reading state information... Done
unzip is already the newest version.
The following NEW packages will be installed:
  zip
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 326 kB of archives.
After this operation, 513 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main zip armhf 3.0-8 [326 kB]
Fetched 326 kB in 1s (168 kB/s)
Selecting previously unselected package zip.
(Reading database ... 121836 files and directories currently installed.)
Preparing to unpack .../archives/zip_3.0-8_armhf.deb ...
Unpacking zip (3.0-8) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up zip (3.0-8) ...

其次是安裝 Apache+PHP+MySQL 伺服器, 參考 :

# 在樹莓派上架設 PHP+MySQL 網站伺服器

更新套件清單與升級套件這裡就不紀錄了, 因為升級很冗長 (1 個小時喔, 而且這次不會在途中詢問 lightdm.conf 的版本問題了). 其實我覺得不用更新升級, 直接輸入下面兩個指令安裝 Apache 與 PHP 就可以了 : 

$ sudo apt-get install apache2   

$ sudo apt-get install php5 libapache2-mod-php5   

安裝完畢後, /var 底下就會產生 www/html 目錄出來, 這就是放 PHP 網頁檔的地方, 不過須先重啟 Apache 伺服器才會運作 :

$ sudo service apache2 restart

接著安裝 MySQL 資料庫, 執行下列兩個指令 :

$ sudo apt-get install mysql-server mysql-client php5-mysql

$ sudo apt-get install php5-mcrypt

最後是安裝 phpMyAdmin 資料庫管理模組, 因為之前下載的 4.6.6 版 .bz 檔在格式化 SD 卡前有先備份出來, 所以直接用 WinSCP 從 PC 傳回樹莓派的 /home/pi 下用 tar 指令解壓即可, 不需再用 wget 指令下載 (因為 4.6.6 還是最新的版本) :

$ tar -jxf phpMyAdmin-4.6.6-all-languages.tar.bz2  

解開後產生 phpMyAdmin-4.6.6-all-languages 目錄, 實在太長了, 先用 mv 指令將其改為 mysql, 再將 mysql 搬移到 /var/www/html 目錄下 : 

$ mv phpMyAdmin-4.6.6-all-languages mysql
$ sudo mv mysql /var/www/html

最後還必須重啟 Apache 資料庫才能使用 phpMyAdmin :

sudo service apache2 restart

但是, 當我以帳號 root 密碼 mysql 連線到 phpMyAdmin 網站時 (此處是 192.168.111.2/mysql), 卻出現如下錯誤 :

"#1045: Access denied for user 'root'@'localhost' (using password: YES)"


奇怪, 我安裝 MySQL 時指定 root 帳號之密碼為 mysql 啊! 怎會無法登入? 參考了許多網路資料都無法解決. 最後我突然想到, 該不會是當初輸入密碼時是在大寫狀態吧? 果然, 用大寫的 MYSQL 就順利登入了! 所以鍵盤上有無 CAPS LOCK 指示燈很重要!

雖然可以登入 phpMyAdmin 了, 但是要如何把 root 的密碼改回去小寫呢? 我習慣用小寫啊! 我參考下面網站的方法, 順利地更改了 root 的密碼 :

# 解決 MYSQL 登入時,ERROR 1045 (28000) using password: NO 的方法
# mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

pi@raspberrypi:~ $ mysql -u root -p   (以 root 帳號登入)
Enter password:                                   (輸入 MYSQL)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 62
Server version: 5.5.54-0+deb8u1 (Raspbian)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> UPDATE user SET Password=PASSWORD("mysql") WHERE User='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye
pi@raspberrypi:~ $

接下來是安裝 PHP cURL 套件, 參考 :

# 在樹莓派上安裝 cURL 與設定 Crontab

安裝指令如下 :

sudo apt-get install php5-curl

安裝完後須重啟 Apache 伺服器才有效.

$ sudo service apache2 restart

另外要修改 php.ini 將 max_execution_time (執行時間上限) 由預設 30 秒提高為 180 秒 :

sudo nano /etc/php5/apache2/php.ini

最後是安裝 ssmtp, 這是可傳送郵件到 SMTP 伺服器 (例如 Gmail) 的簡單郵件代理程式 MTA (Mail Tranfer Agent) :

安裝指令有兩個 :

$ sudo apt-get install ssmtp
$ sudo apt-get install mailutils

完成後還須編輯 ssmtp.conf 設定檔才能透過 Gmail 傳送郵件 :

sudo nano /etc/ssmtp/ssmtp.conf 

參考 :

在樹莓派上利用 sSMTP 傳送郵件的方法

至此總算完成系統重灌了, 雖然好事多磨, 但也學到了一些經驗. 花了兩天才搞定, 所以趕緊先做個備份, 萬一系統又有問題時就直接從備份映像檔回復, 不用再跑上面程序了.

# 備份樹莓派 SD 卡的方法

2017年2月24日 星期五

踢踏舞

最近在電視上看到黃山石的廣告, 其中女舞者跳著輕快的踢踏舞, 舞鞋敲擊地板的聲音襯托出地板磚的堅硬, 看著女舞者輕盈的舞步也讓人心情快活起來, 踢踏舞真是很有活力的舞蹈啊! 很多人好奇的是, 片中的女舞者是誰呢? 原來是有 "童顏美女" 之稱的台灣舞者簡瑞萍 (Ray), 她在台北有開設工作室.

https://www.youtube.com/watch?v=48LoMlO-aSM


黃山石前一部廣告也是踢踏舞, 也非常好看, 其中女舞者是來自日本福岡的島田惠 :

https://www.youtube.com/watch?v=ekahYlgXbOY


成功的廣告就是在賞心悅目的美學感受中傳達商品的價值. 

從幕後花絮也可以了解拍一部短短的廣告片真是不容易耶!


哈! 有看到配電箱中探頭出來瞧的好奇小貓嗎 (35 秒處)? 

2017-03-29 補充 :

上面島田惠拍的這部, 裡面那首好聽的歌到底是甚麼曲子呢? 在底下回應中也有人問, 原來是美國作曲家 Max Brodie 的 Bird Song : 


這首歌曲調輕快, 讓人聽了彷彿一切不快樂都一掃而空了.

SHIMANO 21 速 VAICHE VX507 鋁合金 700C 彎把公路車

今年度公司福利金第二個用途是買台公路車. 福利社網站最近特價兩款 Shimano 的公路車, 一款是 VAICHE VX507 (特價 8500); 另一款是 VX508 (特價 9900). 兩者差別是齒輪配置, VX507 是 3*7=21 速; 而 VX508 是 2*8=16 速. 據老同學鋒仔說後齒盤數大一點較好, 爬陡坡比較有力. 此兩款公路車前後輪皆可快拆放入攜車袋 (另購), 方便搭火車或高鐵.


正統公路車幾何,專業級設計,入門級價位

液壓成型車架管材,內走線設計,增加簡潔與低風阻的效果
SHIMANO 3*7煞變一體公路車套件,不混搭登山車零件
完美齒比,平路衝刺登山爬坡皆適宜
40mm高框板輪,兼具低風阻及高慣性的衝刺
卡式崑藤花鼓,傳動更直接,升級更有空間
台灣設計,台灣組裝,品質後續有保障
非人為損壞車架保固五年零件一年(不包含消耗性零件,如內外胎、煞車皮等)
100%組裝99%包裝,踏板已組裝完成,只需組裝快拆式前輪及坐管,附工具及說明書
★尺寸47適合身高約165~175公分;尺寸50適合身高約170~180公分
★不含踏板實測約10.6公斤
★本商品已投保國泰產險1000(限台灣地區)
參考 :

# 【南紡購物中心】SHIMANO 21速 VAICHE VX507 鋁合金 700C 彎把公路車 $10800
# 【南紡購物中心】SHIMANO CLARIS 2*8 16速 VAICHE VX508 鋁合金 700C 彎把公路車 $9999
# SHIMANO CLARIS 2*8 16速 VAICHE VX508 鋁合金 700C 彎把公路車 $12800

2017年2月23日 星期四

如何在 PC 的 VNC Viewer 上抓取樹莓派螢幕圖像

最近在寫樹莓派實驗筆記時感到最麻煩的一件事就是抓取樹莓派的 X Window 螢幕, 由於透過 VNC Viewer 遠端登入樹莓派時, 發現用 PrintScreen 無法抓 VNC Viewer 上樹莓派的圖像, 所以我只好用 Apowersoft 的螢幕錄影功能先錄成影像後, 再於播放時抓圖.

這種方式實在很彆扭, 而且畫面也不夠精細. 今天在下面這篇文章中發現, 原來其實 VNC Viewer 是可以抓圖的, 原先不行是因為它預設會將 PrintScrint 之類的特殊鍵傳送回樹莓派的 VNC Server, 導致 PrintScreen 鍵在 PC 上無作用 :

Print screen doesn't work

那要怎麼做才能順利在 PC 上抓取樹莓派螢幕圖像呢? 將滑鼠移到 VNC Viewer 最上方中間的矩形突出物處, 會彈出一個工具列 :


點選其中的 VNC 設定按鈕, 切到 "Input" 頁籤, 將其中的 "Pass special keys to VNC Server"  這項取消勾選即可 :


這樣於 VNC Viewer 上按 PreintScreen 就可以抓到樹莓派螢幕圖像了. 早知道就不用繞遠路了.

關於 VNC Viewer 參考 :

# 樹莓派的遠端桌面控制 : 使用 VNC

好用的 Chrome 應用程式 : EPUB 閱讀器 Readium

平常看的電子書大都是 PDF 檔, 最近找到一本 EPUB 電子書, 但要開啟它卻需要安裝像 Calibre 之類的軟體. 今天找到一款 Chrome 應用程式 Readium, 是安裝在 Chrome 裡當作插件, 可直接在 Crome 上開啟 EPUB 電子書, 字體大又美觀, 比 Calibre 還要好用.

安裝方式是在 Chrome 點選下列連結搜尋 EPUB Reader :

https://chrome.google.com/webstore/search/EPUB%20reader%20for%20Chrome?hl=zh-TW

向下找到 Readium 後按右方的 "加到 CHROME" 即可.


完成後點選 Chrome 工具列上的 "應用程式" 按鈕就可以看到 Readium :


點擊執行 Readium 後按右上角 "+" 選擇 EPUB 檔案即可閱讀了 :



掃地機器人 VBOT i6+

今年福利金加碼到 13500 元, 正在慎重考慮要買甚麼. 今天上公司福利社看到這款 VBOT i6+ 掃地機器人, 價格 $3690 元 (市價 4280 元), 兩三年來一直想買, 最後又打消念頭的掃地機器人, 又重回考慮序列惹 ...

以前都堅持一定要有自動回座充電功能, 但看了介紹之後才知道自動回充並不像想像中好用. 因為面積太大或空間較複雜時它可能會找不到回家的路, 只好限縮為一個房間一個房間去打掃, 回充變成單一房間內回充. 這台掃地機沒有回充, 也沒有預約遙控等功能, 算是很陽春的產品. 但優點是 :
  1. 鋰電池比較耐用 (5 年)
  2. 貼地吸塵效果好
  3. 超大容量集塵盒
底下是幾個廣告影片 :

Vbot 超級鋰電池迷你智慧型掃地機器人 (2合1) i6蛋糕掃地機器人


貴的掃地機比較好用嗎? 實測iRobot vs Vbot i6蛋糕機


Vbot 掃地機 民視推薦-人氣療癒



# Vbot i6 蛋糕掃地機器人【實境拍攝 防纏線+自動升降吸風口 免清噁心滾刷 專利技術篇】


Vbot i6蛋糕掃地機器人 二代極淨濾網 超優清潔能力【實境拍攝 毛髮+貓砂+空氣濾清清潔】 

有考慮高雄與鄉下各買一個, 還沒決定.



2017-04-05 補充 :

今天終於決定上公司福利社買了這台掃地機, 我選討喜的草莓色, 先買一台, 如果好用再買第二台. 


2017年2月22日 星期三

樹莓派 MySQL/phpMyAdmin 無法登入問題

前天晚上登入樹莓派 B 的 phpMyAdmin 時發現登入失敗, 出現如下錯誤訊息 :

"#2002 - Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) — 伺服器沒有回應(或者是伺服器的 socket 沒有被正確的設定)。"

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


想從命令列進入 mysql shell 也失敗 :

pi@raspberrypi:~ $ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

重新啟動 MySQL 伺服器也失敗 :

$ sudo /etc/init.d/mysql restart

pi@raspberrypi:~ $ sudo /etc/init.d/mysql restart
[....] Restarting mysql (via systemctl): mysql.serviceJob for mysql.service failed. See 'systemctl status mysql.service' and 'journalctl -xn' for details.
 failed!

照錯誤訊息下 systemctl 指令, 結果還是無法啟動 MySQL 伺服器 :

pi@raspberrypi:~ $ sudo systemctl status mysql.service -l
● mysql.service - LSB: Start and stop the mysql database server daemon
   Loaded: loaded (/etc/init.d/mysql)
   Active: failed (Result: exit-code) since Tue 2017-02-21 06:51:17 CST; 13min ago
  Process: 24848 ExecStart=/etc/init.d/mysql start (code=exited, status=1/FAILURE)

Feb 21 06:51:17 raspberrypi /etc/init.d/mysql[25575]: 0 processes alive and '/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping' resulted in
Feb 21 06:51:17 raspberrypi mysql[24848]: Starting MySQL database server: mysqld . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . failed!
Feb 21 06:51:17 raspberrypi systemd[1]: mysql.service: control process exited, code=exited status=1
Feb 21 06:51:17 raspberrypi systemd[1]: Failed to start LSB: Start and stop the mysql database server daemon.
Feb 21 06:51:17 raspberrypi systemd[1]: Unit mysql.service entered failed state.

而 journalctl 指令的回應如下 : 

pi@raspberrypi:~ $ sudo journalctl -xn
-- Logs begin at Mon 2017-02-20 22:59:07 CST, end at Tue 2017-02-21 07:13:18 CST. --
Feb 21 07:10:04 raspberrypi CRON[26287]: pam_unix(cron:session): session closed for user pi
Feb 21 07:10:04 raspberrypi CRON[26293]: pam_unix(cron:session): session closed for user pi
Feb 21 07:10:04 raspberrypi CRON[26294]: pam_unix(cron:session): session closed for user pi
Feb 21 07:10:05 raspberrypi CRON[26289]: pam_unix(cron:session): session closed for user pi
Feb 21 07:10:05 raspberrypi CRON[26290]: pam_unix(cron:session): session closed for user pi
Feb 21 07:10:06 raspberrypi CRON[26295]: pam_unix(cron:session): session closed for user pi
Feb 21 07:10:11 raspberrypi CRON[26296]: pam_unix(cron:session): session closed for user pi
Feb 21 07:10:12 raspberrypi CRON[26291]: pam_unix(cron:session): session closed for user pi
Feb 21 07:13:18 raspberrypi sudo[26460]: pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/bin/journalctl -xn
Feb 21 07:13:18 raspberrypi sudo[26460]: pam_unix(sudo:session): session opened for user root by pi(uid=0)

似乎沒啥線索. 用 systemctl 指令重啟也是不成功 :

pi@raspberrypi:~ $ sudo systemctl restart mysql.service
Job for mysql.service failed. See 'systemctl status mysql.service' and 'journalctl -xn' for details.

檢視 /var/log/mysql/error.log 發現可能是資料庫分頁毀損 (page corruption), 可能需要重新安裝 :

pi@raspberrypi:~ $ cat /var/log/mysql/error.log
170221  6:50:43 [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.
170221  6:50:43 [Note] Plugin 'FEDERATED' is disabled.
170221  6:50:43 InnoDB: The InnoDB memory heap is disabled
170221  6:50:43 InnoDB: Mutexes and rw_locks use GCC atomic builtins
170221  6:50:43 InnoDB: Compressed tables use zlib 1.2.8
170221  6:50:43 InnoDB: Using Linux native AIO
170221  6:50:43 InnoDB: Initializing buffer pool, size = 128.0M
170221  6:50:43 InnoDB: Completed initialization of buffer pool
170221  6:50:43 InnoDB: highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 1539448058
170221  6:50:43  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 1539464794
170221  6:50:44  InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
InnoDB: Database page corruption on disk or a failed   (資料庫毀損?)
InnoDB: file read of page 1622.
InnoDB: You may have to recover from a backup.   (要重裝系統?)
..... (很長的 page dump : 略) .....
InnoDB: End of page dump
170221  7:15:21  InnoDB: Page checksum 627908371, prior-to-4.0.14-form checksum 3948757627
InnoDB: stored checksum 3484663501, prior-to-4.0.14-form stored checksum 3948757627
InnoDB: Page lsn 0 20662285, low 4 bytes of lsn at page end 20662285
InnoDB: Page number (if stored to page already) 1622,
InnoDB: space id (if created with >= MySQL-4.1.1 and stored already) 0
InnoDB: Page may be an index page where index id is 3
InnoDB: (index "CLUST_IND" of table "SYS_INDEXES")
InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 1622.
InnoDB: You may have to recover from a backup.
InnoDB: It is also possible that your operating
InnoDB: system has corrupted its own file cache
InnoDB: and rebooting your computer removes the
InnoDB: error.
InnoDB: If the corrupt page is an index page
InnoDB: you can also try to fix the corruption
InnoDB: by dumping, dropping, and reimporting
InnoDB: the corrupt table. You can use CHECK
InnoDB: TABLE to scan your table for corruption.
InnoDB: about forcing recovery.
InnoDB: Ending processing because of a corrupt database page.
170221  7:15:21  InnoDB: Assertion failure in thread 3069522928 in file buf0buf.c line 3623
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
23:15:21 UTC - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed,
something is definitely wrong and this may fail.

key_buffer_size=16777216
read_buffer_size=131072
max_used_connections=0
max_threads=151
thread_count=0
connection_count=0
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 346093 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0 thread_stack 0x30000
information that should help you find out what is causing the crash.

我參考下面這篇試試看能否將 MySQL 系統救回來 :

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

pi@raspberrypi:~ $ sudo service mysql start
Job for mysql.service failed. See 'systemctl status mysql.service' and 'journalctl -xn' for details.
pi@raspberrypi:~ $ ps -A|grep mysql
pi@raspberrypi:~ $ sudo pkill mysql
pi@raspberrypi:~ $ sudo pkill mysqld
pi@raspberrypi:~ $ service mysql restart
Failed to restart mysql.service: Access denied
pi@raspberrypi:~ $ sudo service mysql restart
Job for mysql.service failed. See 'systemctl status mysql.service' and 'journalctl -xn' for details.
pi@raspberrypi:~ $ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
pi@raspberrypi:~ $ systemctl status mysql.service
● mysql.service - LSB: Start and stop the mysql database server daemon
   Loaded: loaded (/etc/init.d/mysql)
   Active: failed (Result: exit-code) since Mon 2017-02-20 23:21:01 CST; 1min 31s ago
  Process: 3821 ExecStart=/etc/init.d/mysql start (code=exited, status=1/FAILURE)

仍然無濟於事, 看來只好將 MySQL 移除重新安裝了. 參考下面這篇 :

# How do I completely remove mysql-server on Debian?

pi@raspberrypi:~ $ dpkg -S /etc/mysql
mysql-server-5.5, mysql-common: /etc/mysql

先用 apt-get remove --purge 'mysql-.*' 指令將 MySQL 完全移除 :

pi@raspberrypi:/var/www/html $ sudo apt-get remove --purge 'mysql-.*'
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'mha4mysql-node' for regex 'mysql-.*'
Note, selecting 'libghc6-hsql-mysql-prof' for regex 'mysql-.*'
Note, selecting 'bacula-common-mysql-dbg' for regex 'mysql-.*'
Note, selecting 'lighttpd-mod-mysql-vhost' for regex 'mysql-.*'
Note, selecting 'virtual-mysql-client' for regex 'mysql-.*'
Note, selecting 'dpm-mysql-copyd' for regex 'mysql-.*'
Note, selecting 'mysql-mmm-agent' for regex 'mysql-.*'
Note, selecting 'libmysql-java' for regex 'mysql-.*'
Note, selecting 'virtual-mysql-server-core' for regex 'mysql-.*'
Note, selecting 'virtual-mysql-testsuite' for regex 'mysql-.*'
Note, selecting 'virtual-mysql-server' for regex 'mysql-.*'
Note, selecting 'libwtdbomysql-dev' for regex 'mysql-.*'
Note, selecting 'mysql-server-5.0' for regex 'mysql-.*'
Note, selecting 'mysql-server-5.1' for regex 'mysql-.*'
Note, selecting 'mysql-server-5.5' for regex 'mysql-.*'
Note, selecting 'mysql-server-5.6' for regex 'mysql-.*'
Note, selecting 'haskell-hsql-mysql-doc' for regex 'mysql-.*'
Note, selecting 'libdbd-mysql-5.1-perl' for regex 'mysql-.*'
Note, selecting 'voms-mysql-plugin-dbg' for regex 'mysql-.*'
Note, selecting 'mysql-navigator' for regex 'mysql-.*'
Note, selecting 'libmysql-ocaml-dev-ep3t6' for regex 'mysql-.*'
Note, selecting 'kexi-mysql-driver' for regex 'mysql-.*'
Note, selecting 'mysql-testsuite-5.5' for regex 'mysql-.*'
Note, selecting 'mysql-testsuite-5.6' for regex 'mysql-.*'
Note, selecting 'mysql-client-core-5.5' for regex 'mysql-.*'
Note, selecting 'mysql-client-core-5.6' for regex 'mysql-.*'
Note, selecting 'mysql-client' for regex 'mysql-.*'
Note, selecting 'libmysql-ocaml' for regex 'mysql-.*'
Note, selecting 'libdatetime-format-mysql-perl' for regex 'mysql-.*'
Note, selecting 'lua-dbi-mysql-dbg' for regex 'mysql-.*'
Note, selecting 'mysql-mmm-tools' for regex 'mysql-.*'
Note, selecting 'mysql-server' for regex 'mysql-.*'
Note, selecting 'mysql-proxy' for regex 'mysql-.*'
Note, selecting 'lua-dbi-mysql-dev' for regex 'mysql-.*'
Note, selecting 'mha4mysql-master' for regex 'mysql-.*'
Note, selecting 'dpm-mysql-srmv22' for regex 'mysql-.*'
Note, selecting 'mha4mysql-manager' for regex 'mysql-.*'
Note, selecting 'libcrypt-mysql-perl' for regex 'mysql-.*'
Note, selecting 'lua5.1-dbi-mysql-dev' for regex 'mysql-.*'
Note, selecting 'lua5.2-sql-mysql-dev' for regex 'mysql-.*'
Note, selecting 'libghc-hsql-mysql-prof' for regex 'mysql-.*'
Note, selecting 'libtime-piece-mysql-perl' for regex 'mysql-.*'
Note, selecting 'gsql-mysql-engine' for regex 'mysql-.*'
Note, selecting 'libdbd-mysql-perl' for regex 'mysql-.*'
Note, selecting 'libnss-mysql-bg' for regex 'mysql-.*'
Note, selecting 'libmysql-diff-perl' for regex 'mysql-.*'
Note, selecting 'libkaya-mysql-dev' for regex 'mysql-.*'
Note, selecting 'libghc-hsql-mysql-dev-1.8.2-8c662' for regex 'mysql-.*'
Note, selecting 'bacula-sd-mysql-dbg' for regex 'mysql-.*'
Note, selecting 'bacula-director-mysql-dbg' for regex 'mysql-.*'
Note, selecting 'mysql-mmm-monitor' for regex 'mysql-.*'
Note, selecting 'libghc6-hsql-mysql-dev' for regex 'mysql-.*'
Note, selecting 'mysql-source-5.5' for regex 'mysql-.*'
Note, selecting 'mysql-workbench' for regex 'mysql-.*'
Note, selecting 'libmysql-ocaml-ep3t6' for regex 'mysql-.*'
Note, selecting 'mysql-client-5.0' for regex 'mysql-.*'
Note, selecting 'mysql-client-5.1' for regex 'mysql-.*'
Note, selecting 'mysql-client-5.5' for regex 'mysql-.*'
Note, selecting 'mysql-client-5.6' for regex 'mysql-.*'
Note, selecting 'libclass-dbi-mysql-perl' for regex 'mysql-.*'
Note, selecting 'mysql-testsuite' for regex 'mysql-.*'
Note, selecting 'libghc-hsql-mysql-dev' for regex 'mysql-.*'
Note, selecting 'virtual-mysql-client-core' for regex 'mysql-.*'
Note, selecting 'pinba-engine-mysql-5.5' for regex 'mysql-.*'
Note, selecting 'mysql-common' for regex 'mysql-.*'
Note, selecting 'handlersocket-mysql-5.1' for regex 'mysql-.*'
Note, selecting 'handlersocket-mysql-5.5' for regex 'mysql-.*'
Note, selecting 'mysql-server-core-5.0' for regex 'mysql-.*'
Note, selecting 'mysql-server-core-5.1' for regex 'mysql-.*'
Note, selecting 'mysql-server-core-5.5' for regex 'mysql-.*'
Note, selecting 'mysql-server-core-5.6' for regex 'mysql-.*'
Note, selecting 'libreoffice-mysql-connector' for regex 'mysql-.*'
Note, selecting 'dpm-mysql-nameserver' for regex 'mysql-.*'
Note, selecting 'libghc6-hsql-mysql-doc' for regex 'mysql-.*'
Note, selecting 'mysql-server-core' for regex 'mysql-.*'
Note, selecting 'voms-mysql-plugin' for regex 'mysql-.*'
Note, selecting 'monodoc-mysql-manual' for regex 'mysql-.*'
Note, selecting 'lua-sql-mysql-dev' for regex 'mysql-.*'
Note, selecting 'mysql-utilities' for regex 'mysql-.*'
Note, selecting 'libghc-hsql-mysql-doc' for regex 'mysql-.*'
Note, selecting 'dpm-mysql-srmv1' for regex 'mysql-.*'
Note, selecting 'dpm-mysql-srmv2' for regex 'mysql-.*'
Note, selecting 'libghc-hsql-mysql-prof-1.8.2-8c662' for regex 'mysql-.*'
Note, selecting 'mysql-workbench-data' for regex 'mysql-.*'
Note, selecting 'lua5.1-sql-mysql-dev' for regex 'mysql-.*'
Note, selecting 'libmysql-ocaml-dev' for regex 'mysql-.*'
Note, selecting 'mysql-mmm-common' for regex 'mysql-.*'
Note, selecting 'libmysql-cil-dev' for regex 'mysql-.*'
Note, selecting 'mysql-server-core-5.5' instead of 'mysql-server-core'
Note, selecting 'dpm-copy-server-mysql' instead of 'dpm-mysql-copyd'
Note, selecting 'dpm-name-server-mysql' instead of 'dpm-mysql-nameserver'
Note, selecting 'dpm-srm-server-mysql' instead of 'dpm-mysql-srmv1'
Note, selecting 'dpm-srm-server-mysql' instead of 'dpm-mysql-srmv2'
Note, selecting 'dpm-srm-server-mysql' instead of 'dpm-mysql-srmv22'
Package 'handlersocket-mysql-5.1' is not installed, so not removed
Note, selecting 'libghc-hsql-mysql-dev' instead of 'libghc-hsql-mysql-dev-1.8.2-8c662'
Note, selecting 'libghc-hsql-mysql-prof' instead of 'libghc-hsql-mysql-prof-1.8.2-8c662'
Note, selecting 'libmysql-ocaml' instead of 'libmysql-ocaml-ep3t6'
Note, selecting 'libmysql-ocaml-dev' instead of 'libmysql-ocaml-dev-ep3t6'
Note, selecting 'lua-dbi-mysql-dev' instead of 'lua5.1-dbi-mysql-dev'
Note, selecting 'lua-sql-mysql-dev' instead of 'lua5.1-sql-mysql-dev'
Note, selecting 'lua-sql-mysql-dev' instead of 'lua5.2-sql-mysql-dev'
Package 'libdbd-mysql-5.1-perl' is not installed, so not removed
Package 'mysql-server-5.1' is not installed, so not removed
Package 'mysql-client-core-5.5' is not installed, so not removed
Package 'mysql-client-core-5.6' is not installed, so not removed
Package 'mysql-client-5.6' is not installed, so not removed
Package 'mysql-server-core-5.6' is not installed, so not removed
Package 'mysql-server-5.6' is not installed, so not removed
Package 'mysql-testsuite-5.6' is not installed, so not removed
Package 'mha4mysql-master' is not installed, so not removed
Package 'mysql-client-5.0' is not installed, so not removed
Package 'mysql-client-5.1' is not installed, so not removed
Package 'mysql-server-core-5.1' is not installed, so not removed
Package 'mysql-server-5.0' is not installed, so not removed
Package 'mysql-server-core-5.0' is not installed, so not removed
Package 'bacula-common-mysql-dbg' is not installed, so not removed
Package 'bacula-director-mysql-dbg' is not installed, so not removed
Package 'bacula-sd-mysql-dbg' is not installed, so not removed
Package 'gsql-mysql-engine' is not installed, so not removed
Package 'handlersocket-mysql-5.5' is not installed, so not removed
Package 'haskell-hsql-mysql-doc' is not installed, so not removed
Package 'kexi-mysql-driver' is not installed, so not removed
Package 'libclass-dbi-mysql-perl' is not installed, so not removed
Package 'libcrypt-mysql-perl' is not installed, so not removed
Package 'libdatetime-format-mysql-perl' is not installed, so not removed
Package 'libghc-hsql-mysql-dev' is not installed, so not removed
Package 'libghc-hsql-mysql-doc' is not installed, so not removed
Package 'libghc-hsql-mysql-prof' is not installed, so not removed
Package 'libghc6-hsql-mysql-dev' is not installed, so not removed
Package 'libghc6-hsql-mysql-doc' is not installed, so not removed
Package 'libghc6-hsql-mysql-prof' is not installed, so not removed
Package 'libkaya-mysql-dev' is not installed, so not removed
Package 'libmysql-cil-dev' is not installed, so not removed
Package 'libmysql-diff-perl' is not installed, so not removed
Package 'libmysql-java' is not installed, so not removed
Package 'libmysql-ocaml' is not installed, so not removed
Package 'libmysql-ocaml-dev' is not installed, so not removed
Package 'libnss-mysql-bg' is not installed, so not removed
Package 'libtime-piece-mysql-perl' is not installed, so not removed
Package 'libwtdbomysql-dev' is not installed, so not removed
Package 'lighttpd-mod-mysql-vhost' is not installed, so not removed
Package 'lua-dbi-mysql-dbg' is not installed, so not removed
Package 'lua-dbi-mysql-dev' is not installed, so not removed
Package 'lua-sql-mysql-dev' is not installed, so not removed
Package 'mha4mysql-manager' is not installed, so not removed
Package 'mha4mysql-node' is not installed, so not removed
Package 'monodoc-mysql-manual' is not installed, so not removed
Package 'mysql-mmm-agent' is not installed, so not removed
Package 'mysql-mmm-common' is not installed, so not removed
Package 'mysql-mmm-monitor' is not installed, so not removed
Package 'mysql-mmm-tools' is not installed, so not removed
Package 'mysql-navigator' is not installed, so not removed
Package 'mysql-proxy' is not installed, so not removed
Package 'mysql-source-5.5' is not installed, so not removed
Package 'mysql-testsuite' is not installed, so not removed
Package 'mysql-testsuite-5.5' is not installed, so not removed
Package 'mysql-utilities' is not installed, so not removed
Package 'mysql-workbench' is not installed, so not removed
Package 'mysql-workbench-data' is not installed, so not removed
Package 'pinba-engine-mysql-5.5' is not installed, so not removed
Package 'voms-mysql-plugin' is not installed, so not removed
Package 'voms-mysql-plugin-dbg' is not installed, so not removed
Package 'libreoffice-mysql-connector' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  libaio1 libdbi-perl libhtml-template-perl libterm-readkey-perl
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  libdbd-mysql-perl* libmailutils4* libmysqlclient18* mailutils* mysql-client* mysql-client-5.5* mysql-common* mysql-server* mysql-server-5.5*
  mysql-server-core-5.5* php5-mysql*
0 upgraded, 0 newly installed, 11 to remove and 17 not upgraded.
After this operation, 90.7 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 131585 files and directories currently installed.)
Removing mysql-server (5.5.54-0+deb8u1) ...
Removing mysql-server-5.5 (5.5.54-0+deb8u1) ...
Purging configuration files for mysql-server-5.5 (5.5.54-0+deb8u1) ...
Removing mysql-client (5.5.54-0+deb8u1) ...
Removing mysql-client-5.5 (5.5.54-0+deb8u1) ...
Removing libdbd-mysql-perl (4.028-2+deb8u2) ...
Removing mailutils (1:2.99.98-2) ...
update-alternatives: using /usr/bin/bsd-from to provide /usr/bin/from (from) in auto mode
Removing libmailutils4:armhf (1:2.99.98-2) ...
Purging configuration files for libmailutils4:armhf (1:2.99.98-2) ...
Removing php5-mysql (5.6.29+dfsg-0+deb8u1) ...
php5_invoke prerm: Disable module mysql for cli SAPI
php5_invoke prerm: Disable module mysql for apache2 SAPI
php5_invoke prerm: Disable module mysqli for cli SAPI
php5_invoke prerm: Disable module mysqli for apache2 SAPI
php5_invoke prerm: Disable module pdo_mysql for cli SAPI
php5_invoke prerm: Disable module pdo_mysql for apache2 SAPI
Purging configuration files for php5-mysql (5.6.29+dfsg-0+deb8u1) ...
Removing libmysqlclient18:armhf (5.5.54-0+deb8u1) ...
Purging configuration files for libmysqlclient18:armhf (5.5.54-0+deb8u1) ...
Removing mysql-common (5.5.54-0+deb8u1) ...
Purging configuration files for mysql-common (5.5.54-0+deb8u1) ...
dpkg: warning: while removing mysql-common, directory '/etc/mysql' not empty so not removed
Removing mysql-server-core-5.5 (5.5.54-0+deb8u1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for libc-bin (2.19-18+deb8u7) ...
Processing triggers for libapache2-mod-php5 (5.6.29+dfsg-0+deb8u1) ...

移除完畢後重新安裝 MySQL 伺服器 :

pi@raspberrypi:/var/www/html $ sudo apt-get install mysql-server mysql-client php5-mysql
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  guile-2.0-libs libgc1c2 libgsasl7 libkyotocabinet16 libntlm0 libunistring0 mailutils-common
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  libdbd-mysql-perl libmysqlclient18 mysql-client-5.5 mysql-common mysql-server-5.5 mysql-server-core-5.5
Suggested packages:
  mailx tinyca
The following NEW packages will be installed:
  libdbd-mysql-perl libmysqlclient18 mysql-client mysql-client-5.5 mysql-common mysql-server mysql-server-5.5 mysql-server-core-5.5 php5-mysql
0 upgraded, 9 newly installed, 0 to remove and 17 not upgraded.
Need to get 0 B/7,542 kB of archives.
After this operation, 87.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Preconfiguring packages ...
Selecting previously unselected package mysql-common.
(Reading database ... 131205 files and directories currently installed.)
Preparing to unpack .../mysql-common_5.5.54-0+deb8u1_all.deb ...
Unpacking mysql-common (5.5.54-0+deb8u1) ...
Selecting previously unselected package libmysqlclient18:armhf.
Preparing to unpack .../libmysqlclient18_5.5.54-0+deb8u1_armhf.deb ...
Unpacking libmysqlclient18:armhf (5.5.54-0+deb8u1) ...
Selecting previously unselected package libdbd-mysql-perl.
Preparing to unpack .../libdbd-mysql-perl_4.028-2+deb8u2_armhf.deb ...
Unpacking libdbd-mysql-perl (4.028-2+deb8u2) ...
Selecting previously unselected package mysql-client-5.5.
Preparing to unpack .../mysql-client-5.5_5.5.54-0+deb8u1_armhf.deb ...
Unpacking mysql-client-5.5 (5.5.54-0+deb8u1) ...
Selecting previously unselected package mysql-server-core-5.5.
Preparing to unpack .../mysql-server-core-5.5_5.5.54-0+deb8u1_armhf.deb ...
Unpacking mysql-server-core-5.5 (5.5.54-0+deb8u1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up mysql-common (5.5.54-0+deb8u1) ...
Selecting previously unselected package mysql-server-5.5.
(Reading database ... 131397 files and directories currently installed.)
Preparing to unpack .../mysql-server-5.5_5.5.54-0+deb8u1_armhf.deb ...
Unpacking mysql-server-5.5 (5.5.54-0+deb8u1) ...
Selecting previously unselected package mysql-client.
Preparing to unpack .../mysql-client_5.5.54-0+deb8u1_all.deb ...
Unpacking mysql-client (5.5.54-0+deb8u1) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.5.54-0+deb8u1_all.deb ...
Unpacking mysql-server (5.5.54-0+deb8u1) ...
Selecting previously unselected package php5-mysql.
Preparing to unpack .../php5-mysql_5.6.29+dfsg-0+deb8u1_armhf.deb ...
Unpacking php5-mysql (5.6.29+dfsg-0+deb8u1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for systemd (215-17+deb8u6) ...
Processing triggers for libapache2-mod-php5 (5.6.29+dfsg-0+deb8u1) ...
Setting up libmysqlclient18:armhf (5.5.54-0+deb8u1) ...
Setting up libdbd-mysql-perl (4.028-2+deb8u2) ...
Setting up mysql-client-5.5 (5.5.54-0+deb8u1) ...
Setting up mysql-server-core-5.5 (5.5.54-0+deb8u1) ...
Setting up mysql-server-5.5 (5.5.54-0+deb8u1) ...
170222 20:55:27 [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.
170222 20:55:27 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
170222 20:55:27 [Note] /usr/sbin/mysqld (mysqld 5.5.54-0+deb8u1) starting as process 30672 ...
insserv: warning: script 'K01vncboot' missing LSB tags and overrides
insserv: warning: script 'vncboot' missing LSB tags and overrides
Job for mysql.service failed. See 'systemctl status mysql.service' and 'journalctl -xn' for details.
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing package mysql-server-5.5 (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up mysql-client (5.5.54-0+deb8u1) ...
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
Setting up php5-mysql (5.6.29+dfsg-0+deb8u1) ...

Creating config file /etc/php5/mods-available/mysql.ini with new version
php5_invoke: Enable module mysql for cli SAPI
php5_invoke: Enable module mysql for apache2 SAPI

Creating config file /etc/php5/mods-available/mysqli.ini with new version
php5_invoke: Enable module mysqli for cli SAPI
php5_invoke: Enable module mysqli for apache2 SAPI

Creating config file /etc/php5/mods-available/pdo_mysql.ini with new version
php5_invoke: Enable module pdo_mysql for cli SAPI
php5_invoke: Enable module pdo_mysql for apache2 SAPI
Processing triggers for libc-bin (2.19-18+deb8u7) ...
Processing triggers for systemd (215-17+deb8u6) ...
Processing triggers for libapache2-mod-php5 (5.6.29+dfsg-0+deb8u1) ...
Errors were encountered while processing:
 mysql-server-5.5
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

如上黃色凸顯部分所示, 重新安裝時出現錯誤, 仍然是無法啟動 MySQL 服務, 所以重新安裝完成後仍然無法登入 phpMyAdmin. 因為對 Linux 不熟, 看來只有重新安裝系統了.

參考 :

Can't start mysql service [closed]  (無用)
How to remove MySQL completely with config and library files?
# The MySQL Command-Line Tool