Select Page

Knowledge Base

連接到 MariaDB 10 的方法

MariaDB 5 uses port 3306.
You connect to the database as : localhost

MariaDB 10 uses port 3307.
You connect to the database as : 127.0.0.1:3307

You can alter it in the wp-config.php file where it says :
/** MySQL hostname */ define(‘DB_HOST’, ‘localhost’);

*********************************************************

自己的Wordpress Blog使用MariaDB 5 已經很長時間了,每次更新Wordpress都提示數據庫版本太老了,今天有空就研究了下怎麼遷移到MariaDB 10。

當然首先就是在群暉的套件中心安裝MariaDB 10,啟動打開面板然後配置密碼。

如果使用TCP/IP協議訪問數據庫,記得勾選啟用。

MariaDB 5的端口是3306

MariaDB 10的端口是3307,勾選上TCP/IP連接選項應用生效。

接下來就是遷移數據庫了,使用phpMyAdmin登錄MariaDB 5 然後導出wordpress的數據庫為sql格式文件,然後再打開MariaDB 10導入之前的備份數據庫。

然後來到Wordpress的配置文件wp-config.php進行修改:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'your_user');

/** MySQL database password */
define('DB_PASSWORD', 'your_password');

/** MySQL hostname */
define('DB_HOST', 'localhost');

因為之前的MariaDB 5使用的是3306的默認端口,所以配置裡面的DB_HOST直接用localhost就可以默認連上去。

更新的MariaDB 10端口改變成了3307,而且localhost需要改為127.0.0.1,就需要自己定義如下:

/** MySQL hostname */
define('DB_HOST', '127.0.0.1:3307');

其實更安全的配置是用sock連接。

/** MySQL hostname */
define('DB_HOST', 'localhost:/run/mysqld/mysqld10.sock');

確定改為sock後,wordpress可以正常顯示,就可以把麵板的啟動TCP/IP連接選項關閉提高安全性。

這樣子就完成了數據庫的遷移。

Was this helpful?