星期一, 11月 22, 2004

mysql server 安裝後的設定

1. 以 mysql 客戶端連線程式,用 mysql server 管理員的身份連進 mysql 資料庫
# mysql -u root mysql
Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -AWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1 to server version: 3.23.46Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

2. 設定 mysql server 管理員的登入密碼為 abc123
mysql> update user set password=password("abc123") where user="root";
Query OK, 2 rows affected (0.01 sec)Rows matched: 2 Changed: 2 Warnings: 0

3. 更新資料庫,使設定立即生效
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

4. 離開資料庫
mysql> quit
Bye

5. 再登入 mysql server,但這次加上 -p,登入時將會詢問密碼
# mysql -u root -p mysql
Enter password:
Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -AWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3 to server version: 3.23.46Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

以下為資料庫系統管理範疇
6. 建立資料庫 abc
mysql> create database abc;
Query OK, 1 row affected (0.05 sec)

7. 開放資料庫所有權限給來自 localhost 以密碼 abc246 登入的使用者 abcadm
mysql> grant all on abc.* to abcadm@localhost identified by "abc246";
Query OK, 0 rows affected (0.00 sec)

8. 開放資料庫所有權限給來自任何地方以密碼 abc369 登入的使用者 abcadm
mysql> grant all on abc.* to abcadm@"%" identified by "abc369";
Query OK, 0 rows affected (0.00 sec)

以上兩個例子雖然都是使用者 abcadm,但密碼及可登入的地方皆不一樣,是因為mysql server會將之視為兩個不同的使用者

9. mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>

沒有留言: