本帖最後由 IT_man 於 2014-12-31 09:25 編輯
- B3 ]: R9 P9 b2 S
7 K' |% g# {/ D1 _7 ~1 t【說明】( q9 x. ]+ o$ U: b& ]# f3 U
MySQL資料庫授權有分成本機及遠端,例如,一個帳號綁定給localhost的話,那該帳號只能在MySQL資料庫本機使用,要開放給遠端主機連線到MySQL資料庫主機的話,那就必須將帳號綁定給遠端主機使用,下方介紹方式都是授權或刪除所有權限,MySQL權限有很多可以參考下列:
+ i1 O3 }, v! v) ~ m6 ~ f5 S9 |# o0 L
) b2 b- T# J4 B' m" S0 w3 ` c+ C5 j/ P0 H, _& K
資料庫(DateBase)十五種權限:' a: v1 I5 p2 d8 I7 N8 k
; o/ @9 a4 W4 b$ ]
7 i1 r) ^2 {3 r6 h5 XALL PRIVILEGES、ALTER、CREATE、DELETE、DROP、FILE、INDEX、INSERT、PROCESS、REFERENCES、RELOAD、SELECT、SHUTDOWN、UPDATE、USAGE
. ]9 {# L+ A% g
4 M! V8 [2 N3 u) b5 f- a1 h6 K$ S5 u5 r/ W! b
. h6 E! { n$ L: ^
- _* ]' z( g, O% Q8 E. b# a資料表(Table)八種權限:) G- O9 L" a) c5 j5 @# u5 j7 D4 C/ F
- @3 q9 r7 `2 {! U: z6 `
/ f. r' e# }. S9 NSELECT、INSERT、UPDATE、DELETE、CREATE、DROP、INDEX、ALTER
9 ?, R: l. C9 `; L4 b% J- ?+ m( f# S; W
" {( e/ h6 u: L
( E" i4 e& _5 d% `
1 M3 P, I0 r+ i @資料欄(column)三種權限:$ Z ^* h* W( u3 ]8 ~9 ^7 |" g9 d
, `) U' U9 g1 l: ~, I
# R* F3 D! ?7 aSELECT INSERT UPDATE2 c. t8 T' ~; r, X2 E0 b1 t/ t
3 l7 f4 ]1 u x3 n$ ], W: a
0 ~, |( I3 K+ g, Q% A' Q7 {6 m j8 l4 A ?" d. e2 @
【實例:】
" y1 L7 ~% l+ r5 V( @9 _8 t; Q4 I, {2 G; o. y' p
1 b" q9 q+ H" O
[root@localhost ~]# mysql -u root -p, B3 A+ C) O# R
Enter password:( a+ m: a+ G, K8 p' w
Welcome to the MySQL monitor. Commands end with ; or \g.
8 @4 Y( T1 d$ K0 d, c# H- BYour MySQL connection id is 2
+ b1 {7 r& P) Y2 m& _Server version: 5.1.52 Source distribution
& u( L9 d, K' X$ }) eCopyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
1 n& u, F! F g1 F L1 OThis software comes with ABSOLUTELY NO WARRANTY. This is free software,) B% K& Y5 S# @- f
and you are welcome to modify and redistribute it under the GPL v2 license
/ E" W; u+ S1 x, Q" N7 B. w$ ?& T- f. {9 B8 A1 C
; K9 l" e( R5 x7 c: ?9 j/ ~% W
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
) {6 b0 T' L# `5 n2 M* S7 {5 _# o: x/ f) e9 A
$ {: J7 W% i" X+ w) [( j% Xmysql> grant all privileges on *.* to test@localhost identified by '1234567'; //第一個星號是database,第二個星號是table! K7 l+ l. [# K [* p
& c. I" }! H; {3 |
# U5 Y" L, J- l: u" H+ SQuery OK, 0 rows affected (0.00 sec) //建立test帳號本機權限
, w5 T; }2 S) \2 B5 X" s: J
4 c( d/ X& [' X; K9 R/ ?- |( z( m7 o" {2 @5 X
mysql> grant all privileges on *.* to [email protected] identified by '1234567';" {& o) h, x4 ?" U- s! Z5 x: k7 x
+ {! l I: U n5 V: ^& W) E
# O0 c! E! X; y- s0 vQuery OK, 0 rows affected (0.01 sec) //建立test帳號遠端權限9 Q" b' p0 ~* b% p' y5 Y
# F Q# |# g5 @, a5 I
7 \$ |0 a5 D% y% V6 J/ H) _; q( h: k: f6 J2 [
mysql> select host,user from mysql.user; //查詢MySQL所有授權帳號+ [$ y% K) u* F2 F% l. G2 A. g
1 l1 |" v, q; a( v5 d5 k9 Q
3 a/ q8 ?! K' i5 i* n" k
+-----------------------+-------+% N9 L( h9 u( t6 r4 D! d5 L' m
| host | user |
, f( X5 H! c U6 t; J2 r$ Z+-----------------------+-------+) j: c! |6 }( l2 M
| 127.0.0.1 | root |
0 E) {/ [8 q) C$ b+ l: J. k| 192.168.1.2 | test | //帳號test遠端授權" {0 A6 H% q* k) s8 u
| localhost | |
& c8 S$ m& e5 O* T, M| localhost | test | //帳號test本機授權5 B7 v2 ^7 ]; |. N( I1 d
| localhost | root |! I& n! ?1 e* |$ n. F. t' h( U
| localhost.localdomain | |
4 V3 ?. S5 L* b) f. r| localhost.localdomain | root |* ~0 n/ A5 @' o6 R( v
+-----------------------+-------+' }: a4 v. A" \- ?4 m- P
7 rows in set (0.00 sec)/ W- Z; _( }& x' w# {2 x
% u; E& Z1 O% h' n
6 g. k: q* `2 }! D, N# Amysql> quit //離開MySQL6 w+ E9 O( ]' _# H. d l6 e7 ^
Bye" L ^' G7 ^9 h6 [' m
[root@localhost ~]
! B v! f* }$ T4 G5 B: ~3 y) b; K
p.s 其他mysql 重要語法請參考http://mail.hmes.kh.edu.tw/~jona/redhat/mysqlphp/mysqlsyntax.htm) L2 _! ~6 Q. D2 f( W6 z
" q. M! X+ ?3 ]$ R. {/ q
8 O( b( X8 _7 z" W |
|