tid=196& 本帖最後由 IT_man 於 2014-12-31 09:25 編輯
6 i' A* F' q& P& I, t, y0 j m# _& f, `) T" H( l& Z
【說明】
* [0 t2 }5 H; F1 R3 G$ rMySQL資料庫授權有分成本機及遠端,例如,一個帳號綁定給localhost的話,那該帳號只能在MySQL資料庫本機使用,要開放給遠端主機連線到MySQL資料庫主機的話,那就必須將帳號綁定給遠端主機使用,下方介紹方式都是授權或刪除所有權限,MySQL權限有很多可以參考下列:
4 l5 s- q& [2 v; E5 g) z1 o
6 A1 ?: F" `2 e/ [) l" k$ u3 w0 x" v9 O% x* E
: Z! e0 s* _/ R C+ D$ E- ~資料庫(DateBase)十五種權限:
- \& x3 R" H& q# k F8 ?% C6 i( l2 U& N7 ?1 Q
# e: _8 E# k6 k: j4 }+ J- xALL PRIVILEGES、ALTER、CREATE、DELETE、DROP、FILE、INDEX、INSERT、PROCESS、REFERENCES、RELOAD、SELECT、SHUTDOWN、UPDATE、USAGE
+ s1 K, Z/ s. K' b2 S" ^0 }# L( g& E, u7 @
. h, C3 c2 y* p2 _
7 C' Y) x h: G4 |0 Z) j6 [+ h4 o7 N* r5 ^2 |! ?* r
資料表(Table)八種權限:
5 h7 g2 T _' a! l7 n( |; ~0 K& |; Y! I
' N4 {% E- ?9 f( A/ b' O
( v$ G8 W* \) D( v3 o: ?9 VSELECT、INSERT、UPDATE、DELETE、CREATE、DROP、INDEX、ALTER1 W( f9 B7 o9 G* e# o
( T* u! w+ P- k/ }/ M+ G
: Y# C: a* G l( ?/ W; n5 P/ f6 f
% f+ t* {& P$ h& b; a6 W/ q
. ~/ x3 t1 C% v( w
資料欄(column)三種權限:3 z; [4 G5 c7 c* i' q- ^+ ~1 E& I
2 I3 R: D6 A( r4 g) @" s
2 |6 W* O, w/ I- S8 O2 E* L* _* pSELECT INSERT UPDATE6 I- n: Q) @# c: G% U) O
4 m9 W' }% P5 X0 [% T
: q2 k% P4 A$ D8 U* i/ M
0 M1 {1 h$ |7 C) H【實例:】% L- e3 n- j- q0 @
! h3 h3 @5 M, L: q3 j
A8 U6 l6 W- s- |' E8 D1 [[root@localhost ~]# mysql -u root -p! t# H( J; |5 Y8 H2 M# q3 f; W" n
Enter password:! a/ |2 S& p4 |! ~: \
Welcome to the MySQL monitor. Commands end with ; or \g.
* C7 w9 d6 z* ?! G6 u1 i4 q' P8 NYour MySQL connection id is 22 G' D* T0 K6 W3 _: e- l
Server version: 5.1.52 Source distribution
$ O- z. C, V) Z9 X/ H) ~Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.& S) |. r1 S+ v. E# W E
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
' ]8 g& y! o2 Q1 _5 uand you are welcome to modify and redistribute it under the GPL v2 license$ o! i0 u; X& W% B/ q
( ]+ n | j2 s7 M& P/ E
& z: W& Z M; Q- E. {
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
* p4 g. D) H2 `; |8 J! r, R: X: ^% h; E v% {
& u- ?6 j3 h4 \; Z9 C, ]
mysql> grant all privileges on *.* to test@localhost identified by '1234567'; //第一個星號是database,第二個星號是table
# x/ n8 Q7 W( }+ ]* X; W1 u
3 @ B) C# w: z: ]& W! e1 v! `3 e! f" y! O8 w g& v
Query OK, 0 rows affected (0.00 sec) //建立test帳號本機權限
/ R0 C$ I7 Y( g3 X
9 ?* j* X) ? ^* a1 E/ [4 |& n9 q' f1 W" v# Q# S2 C5 u4 ^$ r& i
mysql> grant all privileges on *.* to test@192.168.1.2 identified by '1234567';* k, F9 d& ?& p" @- G
8 G C3 c4 {, w; K4 J$ Y8 ~* N( y! h+ X3 c0 _: u+ k
Query OK, 0 rows affected (0.01 sec) //建立test帳號遠端權限7 Z( K$ f; @8 O; z2 d
0 i7 x4 [. K5 e/ o1 f
- @ W8 |9 |0 h ^ g h% [; d: H* f2 A# Y' W" K h1 y- w- r+ F
mysql> select host,user from mysql.user; //查詢MySQL所有授權帳號
; w0 u! Q% ^& w+ H
; w/ U: a$ j! `. ?, a: V i! a. ], L5 }% l4 Q
+-----------------------+-------+
1 h, W2 q- @- W9 ~. |" W| host | user |% T" k7 Z* r( P$ j/ ^! f
+-----------------------+-------+
1 g- o! l3 ~+ q) V: _| 127.0.0.1 | root |
1 Q: k$ s R$ E- h! Z| 192.168.1.2 | test | //帳號test遠端授權
, b& {- g: _0 M% j Q| localhost | |
_1 a/ N0 s) l w* [ r| localhost | test | //帳號test本機授權
5 k; o2 s% y, g" {, x| localhost | root |) S7 F6 l; k: X- h, P) P- U$ ^
| localhost.localdomain | |
2 O3 i7 \' W `7 F| localhost.localdomain | root |
4 h3 s( y& L! G o6 m9 |+-----------------------+-------+
8 Z# N2 @3 O+ ?( |3 f, n7 rows in set (0.00 sec)& g0 i/ R. e( c9 D5 A3 p
# B* V4 Z+ o- ?2 t& {) V6 W+ Y9 p( ^5 B. l& e$ A- L
mysql> quit //離開MySQL
: A7 F' l, h- g) a; W6 OBye4 m6 R% q5 m5 ^* l
[root@localhost ~]3 E* D0 X# d+ z: u
2 M) m3 g4 A; I. g5 k, r& O" R8 a, l
p.s 其他mysql 重要語法請參考http://mail.hmes.kh.edu.tw/~jona/redhat/mysqlphp/mysqlsyntax.htm0 C% x; N- G% Q% u# K
$ o6 u) {( d1 `- X7 C
5 g2 O# F% `, F: Q A* W" O' _' _* O1 P" [
|