安裝並使用phpMyAdmin管理MySQL資料庫
最後更新:2017-02-28
來源:互聯網
上載者:User
mysql|資料|資料庫 學會使用基於Web資料庫的管理工具phpMyAdmin。
如果使用合適的工具,MySQL資料庫的管理就會為得相當簡單。應用MySQL命令列方式需要對MySQL知識非常熟悉,對SQL語言也是同樣的道理。不僅如此,如果資料庫的訪問量很大,列表中資料的讀取就會相當困難。
當前出現很多GUI MySQL客戶程式,其中最為出色的是基於Web的phpMyAdmin工具。這是一種MySQL資料庫前台的基於PHP的工具。PhpMyAdmin的缺點是必須安裝在你的Web伺服器中,所以如果沒有合適的存取權限,其它使用者有可能損害到你的SQL資料。
功受獎者PhpMyAdmin的安裝過程非常簡單。從http://www.phpmyadmin.net/下載PhpMyAdmin,當前最新版本是2.6.4-pl3。將下載檔案解壓縮到你選擇的路徑,比如 /srv/www/domain.com/html/admin。在將phpMyAdmin與資料庫連接之前,請確保phpMyAdmin處於受保護狀態,其中可以通過建立一個an .htaccess檔案來完成:
<code>
AuthUserFile /srv/www/domain.com/.htpasswd
AuthGroupFile /dev/null
AuthName adminAuthType basic
<Files *>
Order Deny,Allow
Deny From All
Allow From localhost
require user admin
satisfy any
</Files>
</code>
以上程式碼片段使得假設路徑/srv/www/domain.com沒有受保護因此.htaccess檔案處於Web路徑之外(比如Apache中的 DocumentRoot為/srv/www/domain.com/html)。使用htpasswd工具建立 /srv/www/domain.com/.htpasswd檔案:Create the /srv/www/domain.com/.htpasswd file using the htpasswd tool:
<code>
# htpasswd -cm /srv/www/domain.com/.htpasswd admin
</code>
一旦你已經提供了管理員的密碼,可以編輯包含phpMyAdmin 的config.inc.php檔案。你將可以編輯$cfg['PmabsoluteUri']關鍵字以指向安裝在伺服器中phpMyAdmin的位置,然後編輯$cfg['Servers']數組。為了快速建立和運行,並且能夠編輯服務器上所有的資料庫,你將需要提供的許可權證明:
<code>
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';$cfg['Servers'][$i]['password'] = 'mysecretrootpass';
</code>
現在你可以進入http://www.domain.com/admin/phpMyAdmin-2.6.4-pl3/並訪問你的MySQL資料,並可將路徑重新命名為phpMyAdmin/以更為方便的訪問。