[心得] MySQL資料庫更換為MariaDB

今早的換換病突然發作,想把系統的MySQL換成MariaDB

以為可以無痛轉移,沒想到一裝好WordPress就掛掉了

花了快一個小時才解決這個問題...以下是這次資料庫更換的紀錄

#備份資料庫 (絕對要先做的步驟)
mysqldump -uroot -p -A --default-character-set=utf8 > mysql.sql

#關閉資料庫
service mysqld stop

#移除資料庫與相關元件
yum remove mysql* mysql-server mysql-devel mysql-libs

#建立 MariaDB 的 YUM Repository
nano /etc/yum.repos.d/mariadb.repo

#以nano編輯開啟 mariadb.repo 後,填入下面的內容並存檔
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

#更新系統
yum update

#下載Maria資料庫
yum install MariaDB-devel MariaDB-client MariaDB-server

#啟動Maria資料庫
service mysql start

#設定開機就執行Maria資料庫
chkconfig mysql on

#初始化Maria資料庫(註1)
/usr/bin/mysql_secure_installation

#將MySQL備份檔導入新的Maria資料庫
mysql -uroot -p < mysql.sql

#資料庫重啟
service mysql restart

上面的步驟都很順利地做完,原本以為就這樣結束了...打開網頁一看

你的 PHP 似乎缺少 WordPress 需要的 MySQL 擴充元件

嗯...現實果然沒有想像中的美好,把上面的訊息Google得知是php-mysql要裝新的

yum install php-mysql 當然沒這麼容易打發

不給裝,還跳出一堆訊息要你先裝那個套件

如:

Error: php70w-common conflicts with php-common-5.3.3-49.el6.x86_64

php70w-common conflicts with php-common-5.3.3-49.el6.x86_64 You could try using --skip-broken to ...略

No package php70w-devel available

Error: xz compression not available

 

在google上面找很多解決方法,大多製造新的問題...不過最後還是被我誤打誤撞找到了 (註2)

yum install mod_php70w php70w-cli php70w-common php70w-gd php70w-imap php70w-ldap php70w-mbstring php70w-mysql php70w-pdo php70w-pear php70w-xml php70w-xmlrpc

我php升級到7,那原本的php-mysql 改成  php70w-mysql  就好了...

打完收工


註1:MariaDB初始化,直接按Enter不給過,輸入原本在MySQL的root密碼就給過

註2:解決方法是看到這篇安裝php7.2時,發現php的相關套件都有加版號,把內文中的72改70沒想到就過了  XD

資料來源:

1.[資料庫] 安裝MariaDB取代MySQL在CentOS 6.x上

2.CentOS 7 安裝 Apache+PHP 7+MySQL+phpMyAdmin+FTP+SSH

3.CentOS7 平滑升級MariaDB 5.5 到10.x 新版本實踐