WordPress 使用Domain socket連接資料庫

WordPress 使用Domain socket連接資料庫 Using WordPress with a MySQL Unix Socket

前言

讀此篇文章時必需要俱備WordPress的使用基礎,其文章主要記錄一些小技巧或語法快速使用,有不能理解之處請下留言處留言。

問題

資料庫提供Domain socket連線方式,Wordpress也使用該方式

1.確認資料庫提供的Domain socket位址 在Linux主機內執行netstat -ln|grep "unix.*mysql"取得結果:

root@SAN-3:/volume1/web# netstat -ln|grep "unix.*mysql"
unix  2      [ ACC ]     STREAM     LISTENING     23090584 /run/mysqld/mysqld10.sock
root@SAN-3:/volume1/web#


/run/mysqld/mysqld10.sock記錄起來,等一下要提供至Wordpress設定。

2.開啟Wordpress設定檔wp-config.php 增加或尋找DB_HOST關鍵字,加入或取代內容:

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

這是告訴Wordpress要使用Domain socket方式連接,其帳號、密碼、資料表設定方式相同,如:

define('DB_NAME', 'web_wp');
define('DB_USER', 'root');
define('DB_PASSWORD', '123456');