52AV手機A片王|52AV.ONE

標題: [mysql]權限設定(包含遠端存取) [打印本頁]

作者: IT_man    時間: 2014-12-31 08:01
標題: [mysql]權限設定(包含遠端存取)
本帖最後由 IT_man 於 2014-12-31 09:25 編輯
/ S' w) D0 y8 f* h& M, B5 |( Q/ Y0 N9 H# s" o
說明
/ _. Y7 |; `' WMySQL資料庫授權有分成本機及遠端,例如,一個帳號綁定給localhost的話,那該帳號只能在MySQL資料庫本機使用,要開放給遠端主機連線到MySQL資料庫主機的話,那就必須將帳號綁定給遠端主機使用,下方介紹方式都是授權或刪除所有權限,MySQL權限有很多可以參考下列:
0 Y$ q$ S3 M. d3 u2 H( w4 Z* V5 \/ Z# ~# W/ o9 B' f
# S( }% |: U; r( H/ |- y
' G0 U; u5 X4 S* E- p* H
資料庫(DateBase)十五種權限:
$ m7 S- Y5 X' G: N; o
7 u# q( q, e/ j; `! h4 f' p2 o7 w; ~

( l) R: U# y4 u. SALL PRIVILEGES、ALTER、CREATE、DELETE、DROP、FILE、INDEX、INSERT、PROCESS、REFERENCES、RELOAD、SELECT、SHUTDOWN、UPDATE、USAGE- K9 W8 s4 F& H) X. S
- q6 R3 f# z0 Z3 \3 c% _9 i
7 u# s- I% x/ R+ m& W1 ]
$ s" ]6 k; ^9 q9 e

' j( A7 E. o( z3 e資料表(Table)八種權限:7 F1 B  O3 S" N: A

1 H; u4 T) |# q" d2 |
# K3 ~3 c+ |# B: w+ G$ Y
SELECT、INSERT、UPDATE、DELETE、CREATE、DROP、INDEX、ALTER
1 G& Z+ a* p7 r& y
* v0 S4 Y( f  {4 _4 n, k

3 t$ g7 D, L+ t2 G0 F( d' u0 M+ A5 _2 _4 J" @

! x& A* g- F' z資料欄(column)三種權限:
" J; S4 u) W( s1 \/ x( O* X! \" A: q+ u" n7 X& V" U$ x+ l
1 T* Q' M# B" d/ ^2 {
SELECT INSERT UPDATE5 C7 y+ c  _3 q) }% m4 Z7 i9 i

. j: _- R# `% h+ Z
! R5 r4 H- y* \7 r& f

8 m4 O' r$ w0 k! i+ t實例:
  f1 P2 ^: e2 O4 U3 ~0 K1 V
; ^( a$ ?+ B# |
) s+ y2 a8 B- i9 b& _
[root@localhost ~]# mysql -u root -p+ C& K  I' w% b0 a, C5 @0 G
Enter password:
/ R7 p3 A1 I8 M8 f: qWelcome to the MySQL monitor.  Commands end with ; or \g.
  U! W3 _* O7 v. h# n# Q* C1 C/ }9 iYour MySQL connection id is 23 g5 R& `- M( ]; z3 |9 l! R
Server version: 5.1.52 Source distribution
5 S& k) T& j$ [/ v& bCopyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  t, Y0 d8 C) `( [3 d  F3 dThis software comes with ABSOLUTELY NO WARRANTY. This is free software,
5 ^4 y$ ~$ T( S/ C3 Kand you are welcome to modify and redistribute it under the GPL v2 license* ^9 J6 ~% o" u$ W1 M5 G

# E! w, E  m3 Z, Q/ U7 v1 [) c
0 j! j; Z( b6 z/ A% b* I
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
9 d4 b! d: ~1 O4 k8 G& U6 k2 a- A3 T5 h  z6 e5 z, M: z6 j
% Q1 U7 S# \6 M
mysql> grant all privileges on *.* to test@localhost identified by '1234567'; //第一個星號是database,第二個星號是table& f0 l, S9 y% Z0 e7 Z1 Q

. b/ r. X5 }, j
6 h4 i3 ]8 R* k- s/ D
Query OK, 0 rows affected (0.00 sec)     //建立test帳號本機權限
/ f) X6 x# z; E! m  ^- H* H: Z) D& B1 Z2 L) }+ p
: s  ~' d0 G* y' _; s
mysql> grant all privileges on *.* to test@192.168.1.2 identified by '1234567';
+ W0 H6 X5 u9 Q" x9 L% F( H: w& U3 I+ _5 n4 C7 q( i! C- n

; e1 c( G6 u( _: B: C$ LQuery OK, 0 rows affected (0.01 sec)   //建立test帳號遠端權限
" s& ^) S4 Q- [/ ~( o6 e7 Q; M% K( v3 {3 q( n

9 J, \9 t# X1 t6 v

& A% [$ _4 }: ~9 R  W6 @mysql> select host,user from mysql.user;   //查詢MySQL所有授權帳號
( x* f1 W( N% Q% A8 q) H! U7 D, }7 z1 y

' ], G: P; e* D& x+-----------------------+-------+
& A+ v# s  y+ n2 || host                  | user  |+ H& v1 o" z( {" `
+-----------------------+-------+
  |1 l9 l1 w( ]- n/ J$ U& W| 127.0.0.1             | root  |  M/ P2 [* _( v; q  t2 B7 D
| 192.168.1.2           | test  |       //帳號test遠端授權% a( z( L, Z; I! p- P: G, l
| localhost             |       |; H1 S% r8 m' L" i" r0 E" @
| localhost             | test  |        //帳號test本機授權
# S) J2 L9 Q9 a6 F! c% _+ b| localhost             | root  |
% \2 f- ?! w$ R0 I9 R| localhost.localdomain |       |
- {' y  @4 ^; y" e: Q: p7 ?+ T| localhost.localdomain | root  |  W, @6 n* {& Q8 Q  r0 l- U4 |/ `
+-----------------------+-------+
$ J2 E6 j  T% n7 rows in set (0.00 sec)
2 h% b  J% P% j4 k# R5 g: U  P; X+ G* a6 W2 P) _

: v& x$ J7 R' U5 q: smysql> quit   //離開MySQL7 ?! X" }6 U5 S8 \( z7 R, w
Bye
( p4 j/ W% h" T* V: b[root@localhost ~]. j& q( J$ c# g+ N
- v6 W" L: k3 I7 T8 ?7 _5 S& i) ~
p.s 其他mysql 重要語法請參考http://mail.hmes.kh.edu.tw/~jona/redhat/mysqlphp/mysqlsyntax.htm0 R. ^) p* k" s) v" @$ H' h

! [' N' Y" U: I/ O- g8 y# U
+ a8 A2 s3 E' i




歡迎光臨 52AV手機A片王|52AV.ONE (https://www.52av.one/) Powered by Discuz! X3.2