本帖最後由 IT_man 於 2014-12-31 09:25 編輯
& y1 j4 D, W( u1 c0 f r4 O
/ W2 }' @8 V6 ^% {% b【說明】6 y) r0 D) q- @& v* y+ M
MySQL資料庫授權有分成本機及遠端,例如,一個帳號綁定給localhost的話,那該帳號只能在MySQL資料庫本機使用,要開放給遠端主機連線到MySQL資料庫主機的話,那就必須將帳號綁定給遠端主機使用,下方介紹方式都是授權或刪除所有權限,MySQL權限有很多可以參考下列:
! O- M) Q8 a3 F. s6 \" B! L8 I9 l. R
/ m, K# l( b5 D% y
3 [2 W' u' _& D資料庫(DateBase)十五種權限:
$ q+ j# H7 A* P8 ~2 R" s
S, Z: e; x6 r8 s0 \+ ~7 v6 z2 p" ], R n" j' k
ALL PRIVILEGES、ALTER、CREATE、DELETE、DROP、FILE、INDEX、INSERT、PROCESS、REFERENCES、RELOAD、SELECT、SHUTDOWN、UPDATE、USAGE7 b7 E" A% a- m! L' A8 V2 x w( q
, c, u3 K! l$ p( z& z( ]% {" `; u
+ Q% l& K: ]/ @; w d
: m( h. G2 z" e
/ T/ Z5 N4 A( h) I; B
資料表(Table)八種權限:
) g8 G6 ~5 b' j1 d {' {; A& I k, a& J3 i
3 E7 Y, F2 J9 {6 T
2 T" J( C: x0 C: G3 D, {. k+ }SELECT、INSERT、UPDATE、DELETE、CREATE、DROP、INDEX、ALTER2 F W8 I" \0 f6 k. [
+ ]% A2 A x# q& A! R
' o8 M/ v) `5 m! g
) i7 g# @' n ?
* Y* T! l; g/ n( j6 n) n% V; I資料欄(column)三種權限:
# K+ \) g/ v; q) T4 r! `: }; x7 k) E- a( G/ W) W- f* _
1 z8 c, T Q, T& f
SELECT INSERT UPDATE+ ?6 o& h4 P6 p2 r0 R
' K1 Y0 B, a8 }1 a& o0 p
s4 Y. K R8 s& }8 t2 l
9 v0 T' a3 ~; m4 y【實例:】& T* r6 m$ E9 w) G
7 ~! R) h$ `$ O& I+ ~0 p- _
3 e/ j1 O! Y |. _1 y
[root@localhost ~]# mysql -u root -p, a& [ K: U: @
Enter password:
1 a2 @- B* g5 }Welcome to the MySQL monitor. Commands end with ; or \g.
1 K( J! E% v- u& n$ B) t0 v; C: C& _Your MySQL connection id is 2# Q) ]# _2 H/ i; F( h$ ~
Server version: 5.1.52 Source distribution( Y# U9 u% I% t# y
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.5 Z0 o- `* t5 E6 F' Z- J
This software comes with ABSOLUTELY NO WARRANTY. This is free software,* r8 J" m* }) L7 y/ `. e9 V$ s
and you are welcome to modify and redistribute it under the GPL v2 license
. O. l. m) I: i) q9 P) }& Q' P/ g. l- a4 C
& g% F6 k2 ]" u" z) S- {
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
2 i T3 r3 Q9 i! s( @9 B7 c9 Y h' f9 T9 o
% f" V( M6 u8 n" xmysql> grant all privileges on *.* to test@localhost identified by '1234567'; //第一個星號是database,第二個星號是table
7 g' {0 t6 H, q" f; a( o' u, B* {. K
( y2 x. c4 q# y) {4 k# M( lQuery OK, 0 rows affected (0.00 sec) //建立test帳號本機權限
$ ~/ l' Y9 c; P% ~2 U
' k( H+ Z# M7 } h: s
/ N+ }8 z( l; H' q4 H0 j" Dmysql> grant all privileges on *.* to [email protected] identified by '1234567';
+ u( ]$ j! n* t2 b! w' e2 h
. k, L0 b5 `. ? Z/ w ~
5 x7 v7 o( o4 YQuery OK, 0 rows affected (0.01 sec) //建立test帳號遠端權限/ y A$ f. a. L8 _1 W) [- {
]( R/ \$ L# z5 a7 ~$ Q& E+ r8 {' y/ _
9 T3 F1 p# c0 `mysql> select host,user from mysql.user; //查詢MySQL所有授權帳號1 S6 s; A7 Z) C
3 O9 R% U6 X' ^; S
; }7 L2 q5 A" E$ o. N/ \3 ?+-----------------------+-------+
9 p% B0 b8 r1 i, E/ O| host | user |
& P. d6 @7 G( A7 K5 L+-----------------------+-------+
) P: [: c. r# Q# m7 X* v| 127.0.0.1 | root |, C( ~' @3 }( S7 d0 }/ o; l( {
| 192.168.1.2 | test | //帳號test遠端授權
" [' S G5 L, h| localhost | |
: e$ ?/ v! j/ _: ~| localhost | test | //帳號test本機授權 N' D$ }( j! b( S) @% i
| localhost | root |
* T! @: t7 F+ u& f: O| localhost.localdomain | |; {# n' ^, a: I
| localhost.localdomain | root |
3 o$ ^( `2 m7 ]0 t+-----------------------+-------+
, j K9 m7 Z+ S: _$ M7 rows in set (0.00 sec). k3 @- L0 R. M+ u" t8 z7 }' \
% Y! H* k2 V8 o2 ]
S6 J* f2 O( I6 X. Emysql> quit //離開MySQL* q6 } \* r5 }0 i
Bye7 B' L& q! I, X, X
[root@localhost ~]
+ e: [' v# x- K0 ?' Q0 O8 s2 ?% r, C8 g2 _
p.s 其他mysql 重要語法請參考http://mail.hmes.kh.edu.tw/~jona/redhat/mysqlphp/mysqlsyntax.htm: y+ W* W3 [+ c1 \( d
3 T- Z( t; _' U& L! b( G# o
$ l' D: t! u+ `8 I& A0 W& |- R" Y4 Z
|
|