複製自Benjr.tw(因該站遷移,暫先把好文章收下來,若涉版權,請賜告,立刻移除)
MySQL 資料庫
因為 Drupal 會將資料儲存在 database 中,我們用 Linux 常使用的 MySQL 當成我們的資料庫系統.
因為 Drupal 會將資料儲存在 database 中,我們用 Linux 常使用的 MySQL 當成我們的資料庫系統.
啟動 MySQL
如果要開機時就啟動 MSQL ,使用下面這個指令,就會在每次開機時啟動 MySQL .
| [root@benjr ~]# chkconfig mysqld on |
當然我不希望現在再重開機所以直接用下面的指令將 MySQL 打開.
| [root@benjr ~]# service mydqld start Initializing MySQL database: [OK] Starting MySQL: [OK] |
建立資料庫號密碼
第一次啟動 MySQL 時他會先將我們的資料庫作一些初始化的動作,並在目錄 /var/lib/mysql 下建立相對應的資料.既然都啟動了,那先看看我們能不能連上 MySQL.
| [root@benjr ~]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 to server version: 4.1.20 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> quit; #跳出 MySQL shell的指令是 “quit” 或是 "exit". Bye |
如果你可以看到這個畫面那代表你的MySQL運作正常.不過MySQL 的密碼還沒設定,所以先將密碼設一下,要不然所有的人都可以隨意進入MySQL那是一件很可怕的事.還有剛剛我們使用的指令中的 root 是 MySQL 的使用者,和系統上的 root 是不一樣的帳號,這一點很多人剛開始會搞混,所以現在我們要為 MySQL 的 root 設定密碼.
| [root@benjr ~]# mysqladmin -u root password '123456' |
要設定密碼請使用指令 mysqladmin, -u 就是你的使用者,這邊的 root 是 MySQL 的 root 和系統上的 root 只是名稱相同,這邊修改任何密碼將不會改變 /etc/passwd 的任何東西.括號中的 'password' 就是妳輸入的密碼.這樣下次登入就要使用密碼才能登入.如果你不滿意剛剛輸入的密碼,要修改的話那要加入參數 –p
| [root@benjr ~]# mysqladmin -u root –p password 'abcdef' Enter Password: |
這邊的 Enter Password 是剛剛第一次輸入的密碼,也就是123456,成功之後你的密碼就會變成abcdef.下次要再登入也就是用這個密碼.
開始建立資料庫
我們要為將來使用的 drupal 建立一個資料庫,方法很簡單只要下面幾個步驟,建立一個資料庫名稱為 drupal 以及使用者帳號,我這邊隨便用一個 drupaluser 為範例,你可以依據自己的喜歡來命名.
| [root@benjr ~]# mysql -u root -p Enter password: #輸入MySQL 的 root 密碼,以剛剛的範例是 ‘abcdef’ Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 to server version: 4.1.20 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create database drupal; #這邊就是要建立 drupal專用的資料庫,create database資料庫名稱你可以依據自己的需求做改變,注意每個指令後面都要加上 ";" Query OK, 1 row affected (0.00 sec) mysql> grant all privileges on drupal.* to drupaluser@localhost identified by 'your.password' ; #將剛剛建立的 drupal 資料庫權限給 drupaluser 這個帳號!這邊的 ‘your.password’是指 drupaluser的密碼,你可以依據你的喜好作變更,但是要記住之後的 drupal 會用到, 因為是本機端所以用 @localhost 為連線,不要忘了指令後面都要加上 ";" Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> exit; #大功告成,跳出來吧!!以後再也用不到了MySQL 的指令了. Bye |
試一下剛剛建立好的 drupal資料庫和使用者吧!!
| [root@benjr ~]# mysql -u drupaluser -p Enter password: #這邊要輸入的密碼是 drupaluser 的密碼,我剛剛設定的是 your.password. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 to server version: 3.23.56 mysql> connect drupal; #連線到 drupal 資料庫看一下. Connection id: 7 Current database: drupal #如果你可以用 drupaluser 連線到drupal 資料庫,那代表資料庫的連結沒有問題.可以開始進入安裝 Drupa 了. mysql> show databases; +-------------+ | Database | +-------------+ | drupal | | mysql | | test | +-------------+ 3 rows in set (0.00 sec) #查詢目前所有已經建立的資料庫,mysql 和 test 是系統預設建立好的資料庫. |
移除資料庫
這裡補充一下如果你不滿意剛剛建立好的資料庫,下面是移除資料庫的方法.
| [root@benjr ~]# mysql -u root -p Enter password: #輸入MySQL 的 root 密碼,以剛剛的範例是 ‘abcdef’ Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 to server version: 3.23.56 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> drop database drupal; #這樣就移除掉 drupal 資料庫移除掉之後就不見了千萬要三思ㄚ. |
修復資料庫
至於如何修復 mysql 的 datbase,參考下面的方法.
| [root@benjr ~]# service mysqld stop [root@benjr ~]# cd /var/lib/mysql/drupal [root@benjr ~]# myisamchk –r *.MYI |
更多有關於如何修復 mysql 的 datbase 請參考下面的網頁.
http://dev.mysql.com/doc/refman/4.1/en/repair.html
http://dev.mysql.com/doc/refman/4.1/en/repair.html
忘記密碼
至於忘記密碼的方式如下.
| [root@benjr ~]# service mysqld stop [root@benjr ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & [root@benjr ~]# mysql -u root mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 to server version: 3.23.56 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> update user set password=password('new password') where user='root'; mysql> flush privileges; mysql> exit; #接下來就可以用剛剛的密碼登入你的 mysql 了. [root@benjr ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 to server version: 4.1.20 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. |
沒有留言:
張貼留言