本帖最後由 IT_man 於 2014-12-31 09:25 編輯 $ y( T) m2 {' ?; \% h) t$ y
; [, n4 o% N( n' |. Q/ p
【說明】+ Z8 _3 t$ S8 \/ ^$ n7 V, q6 l2 N w
MySQL資料庫授權有分成本機及遠端,例如,一個帳號綁定給localhost的話,那該帳號只能在MySQL資料庫本機使用,要開放給遠端主機連線到MySQL資料庫主機的話,那就必須將帳號綁定給遠端主機使用,下方介紹方式都是授權或刪除所有權限,MySQL權限有很多可以參考下列:8 X; j5 V: u$ R- ]/ Z- d# j% H2 C
}4 o: g8 G, A' \5 V7 h8 `
8 E7 _% ?& H$ B* L8 z
( D4 Z' m t# c
資料庫(DateBase)十五種權限:
1 z) M3 @2 n+ d- X% {' P, y- T3 Y8 ^
8 _+ C' X! h. U j2 wALL PRIVILEGES、ALTER、CREATE、DELETE、DROP、FILE、INDEX、INSERT、PROCESS、REFERENCES、RELOAD、SELECT、SHUTDOWN、UPDATE、USAGE. L& l1 K% _8 \9 @& V3 H
/ e7 ^$ l* } K3 U4 ]1 r3 g; K" U- e0 k$ C# \! h
; W- ]5 D- `. y9 e( k1 {' q: y! `
/ L% b& v1 B- K3 ]* r
資料表(Table)八種權限:7 K: m: r0 }& L8 |
1 F5 B+ K, @1 D. O6 B. m9 |) e( x' d j/ G6 T
SELECT、INSERT、UPDATE、DELETE、CREATE、DROP、INDEX、ALTER- y8 R( L9 _# G2 T3 F
, \1 `: C! n& p4 E
+ g7 w( w7 y" Q) l0 F
+ B" B8 j7 }) D3 y3 d
3 u1 [9 _. c7 |7 r- \& s資料欄(column)三種權限:% E* C5 g {- v( m3 X
1 M- S d5 E- T3 n7 t+ E
# }4 U5 w7 Q6 z" L/ [SELECT INSERT UPDATE! E' ~4 U6 r( ]" d1 P
. Z9 Z% V" f" l! ^- y* i% U
: ^3 Z! A: f. n7 B; }
% x5 |/ J' P: j4 ~
【實例:】
! ~! [# w( m- f4 r: \# n2 k9 r" v# ?8 u
$ ^( k# Z- C" @( ~
! u6 ]/ w' q* d% U+ }4 T6 Y/ U) E[root@localhost ~]# mysql -u root -p
% E u3 G# c3 \, jEnter password:
1 ?. T7 E m; ^' F" a7 Z6 ]# mWelcome to the MySQL monitor. Commands end with ; or \g./ \: y3 _4 O# r4 D' q/ e
Your MySQL connection id is 2
: B+ K6 D+ K$ ?$ M" N: TServer version: 5.1.52 Source distribution x- d( y0 b. m
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.- h. c; T* K8 ]# i; k, E5 B% r
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
% V* U! k/ z7 cand you are welcome to modify and redistribute it under the GPL v2 license
$ z3 d1 F% E2 V" {# ?. r( y) S; l$ @( C8 K9 M
( K+ F9 p& D+ I1 W; l I [1 d/ s' V
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.$ \6 a6 H" A6 a6 V8 s
$ s+ h$ n% ?& K1 c3 e1 q
1 N* b$ q' K* E' g$ k8 h/ C
mysql> grant all privileges on *.* to test@localhost identified by '1234567'; //第一個星號是database,第二個星號是table5 D/ b, I/ ]2 Y# j( N. A/ I
6 M5 n* V1 Y, q+ O
$ n9 X7 A; v9 z7 p% k4 ~Query OK, 0 rows affected (0.00 sec) //建立test帳號本機權限5 q- n1 I9 X9 n, ~$ R: f
! T" e' Z$ o [* ?& j6 ?* ` K: M5 C% F7 S0 {
mysql> grant all privileges on *.* to [email protected] identified by '1234567';- q: c; U! c' B1 `, |& ?
+ u6 w# e( a }6 f$ d$ R
2 T7 d5 H2 k- Z7 S( QQuery OK, 0 rows affected (0.01 sec) //建立test帳號遠端權限6 h' d) H {6 \0 X! K" J( H
8 G" u* V! f& \2 x: u I! y4 J3 L' N! Z% h( S. Q9 x& s
5 o( u: U% y$ t$ J4 k& Fmysql> select host,user from mysql.user; //查詢MySQL所有授權帳號
# {& ~5 v" H9 x. x
0 I$ H& x0 \ m5 @
9 k9 y! o9 R. Q+-----------------------+-------+
- d6 W) G- W1 K% Z& \| host | user |
* w" n& T; \" I- s% T0 T2 k+-----------------------+-------+- H, T6 K( d+ G4 ~4 Q2 h1 D$ {' x0 U5 [
| 127.0.0.1 | root |, @- j2 N3 j) r( P M
| 192.168.1.2 | test | //帳號test遠端授權
* H# ]) X, p! }, A! @3 }| localhost | |4 Q( g. |1 G7 e% |$ H% ?
| localhost | test | //帳號test本機授權
% V4 i6 m9 B# U: V% Y| localhost | root |. E) T/ V, u' K
| localhost.localdomain | |
8 ?% X" e* r( C9 P- q& ~, W5 x| localhost.localdomain | root |
" Q9 y& I6 w, y+ ~ r2 O+-----------------------+-------+6 Y8 Y9 s+ x$ N1 p+ Y6 A' n
7 rows in set (0.00 sec)2 O+ K% U2 p2 C
) e. V! N' O" b" q# B
. p4 \; Q8 ~; Ymysql> quit //離開MySQL! L) e" Y7 s6 t" B1 n
Bye1 c2 W( u" b& z9 L2 e
[root@localhost ~]
: k5 u: E- c$ L0 T9 V; t% A
1 c# D u* _( M1 v2 j% A7 k2 G" k" Tp.s 其他mysql 重要語法請參考http://mail.hmes.kh.edu.tw/~jona/redhat/mysqlphp/mysqlsyntax.htm" _' L$ k% M" i2 l9 v
' J4 I# w: {' v' j% r! I" _
, D" l: G; q6 Z9 n& t9 b6 d7 H
|
|