'저장용'에 해당되는 글 58건
- 2009.03.23 vi 명령어
- 2009.03.23 samba 설치 , 실행
- 2009.03.20 쉘 프롬프트에서 질의 실행하기.
- 2009.03.20 mysql [12.5.1.3. GRANT Syntax]
- 2009.03.19 mysqldump 사용법
vi 에디터의 세가지 모드
1. 명령어 모드
파일의 편집 작업을 한다 즉, 글자를 지우고, 바꾸고, 복사하고, 다른 곳으로 옮기고, 글자를 찾고, 찾을 글자를 바꾸는 작업을 명령어 모드에서 한다.
2. 삽입 모드
삽입 모드가 아닌 다른 모드에서는 글을 입력할 수 없다. vi 명령어는 먼저 명령어 모드로 실행되므로, 명령어 모드에서 삽입 모드로 오기 위해서는 명령어를 따로 입력해야 한다. 이 떄 입력하는 명령어에 따라서 커서를 기준으로 어느 곳에 글을 입력할지 결정된다.
3. ex 모드(마지막 행 모드)
명령어 모드에서 사용할 수 없는 강력한 검색 치환 기능과 vi 에디터 설정 기능이 있다.
vi 에디터 실행 방법
vi 명령어 다음에 편집할 파일의 이름을 적으면 된다. 이때 명시하는 파일이 존재할 경우는 그 파일을 읽어서 편집하고, 파일이 존재하지 않으면 파일을 새로 만들게 된다.
vi 필수 명령어
1. 이동 명령어
단순히 커서의 위치만 옮기고 파일의 내용은 전혀 변경하지 않는다.
키 |
내용 |
h |
커서를 현재 위치에서 왼쪽으로 한 글자 옮긴다. |
j |
커서를 현재 위치에서 한 라인 아래로 옮긴다. |
k |
커서를 현재 위치에서 한 라인 위로 옮긴다. |
l |
커서를 현재 위치에서 오른쪽으로 한 글자 옮긴다. |
2. 편집 명령어
글자를 추가하거나, 기존에 있는 글자를 삭제할 경우에 사용하는 명령어이다. 입력한 내용을 명령어가 아닌 파일에 입력하는 데이터로서 인식하여 ESC를 누를때까지 입력한 모든 내용이 화면에 출력된다. 글자를 지우는 명령어를 사용하면 지운 글자는 임시 레지스터에 저장된다.
키 |
내용 |
i |
현재 커서가 있는 곳에 글자를 ESC를 누를 때까지 입력한 글자를 추가한다(insert). |
x |
현재 커서가 있는 곳의 글자를 지운다. |
3. 종료 명령어
키 |
내용 |
:w |
현재 편집하는 파일을 저장한다(write). |
:w! |
현재 편집하는 파일을 강제로 저장한다. |
:q |
현재 편집하는 파일을 닫고 vi 에디터를 종료한다(quit). |
:wq |
현재 편집하는 파일을 저장하고 vi 에디터를 종료한다(write & quit). |
:zz |
현재 편집하는 파일을 저장하고 vi 에디터를 종료한다. |
vi 기본 명령어
1. 이동 명령어
키 |
내용 |
w |
커서를 우측 단어의 첫 글자로 옮긴다(Word). |
W |
커서를 우측 단어의 첫 글자로 옮긴다. 단, 단어는 공백으로만 나뉜다(Word). |
e |
커서를 우측 단어의 끝 글자로 옮긴다(End of word). |
E |
커서를 우측 단어의 끝 글자로 옮긴다. 단, 단어는 공백으로만 나뉜다(End of word). |
b |
커서를 좌측 단어의 첫 글자로 옮긴다(Backward). |
B |
커서를 좌측 단어의 첫 글자로 옮긴다. 단, 단어는 공백으로만 나뉜다(Backward). |
→ vi 명령어의 단어 단위의 커서 이동 명령어
키 |
내용 |
0 |
커서를 라인의 첫 글자로 옮긴다. |
^ |
커서를 공백을 나타내는 글자를 제외한 나머지 글자 중에서 라인의 첫 글자로 옮긴다. |
$ |
커서를 라인의 끝 글자로 옮긴다. |
- |
커서를 한 라인 위로 옮기되, 공백을 제외한 나머지 글자 중에서 라인의 첫 글자로 옮긴다. |
+ |
커서를 한 라인 아래로 옮기되, 공백을 제외한 나머지 글자 중에서 라인의 첫 글자로 옮긴다. |
H |
커서를 화면의 첫 라인으로 옮기되, 공백을 제외한 나머지 글자 중에서 라인의 첫 글자로 옮긴다. 파일의 첫 라인이 아니라 현재 보이는 화면의 첫 라인으로 옮긴다는 점에 유의해야 한다(High). |
M |
커서를 화면의 중앙 라인으로 옮기되, 공백을 제외한 나머지 글자 중에서 라인의 첫 글자로 옮긴다. 파일의 중간 라인이 아니라 현재 보이는 화면의 중간 라인임에 유의하자(Middle) |
L |
커서를 화면의 마지막 라인으로 옮기되, 공백을 제외한 나머지 글자 중에서 라인의 첫 글자로 옮긴다. 파일의 제일 마지막 라인이 아니라 현재 보이는 화면의 마지막 라인임에 유의하자(Low). |
nG |
숫자 n이 명시된 경우는 파일의 n번째 라인의 공백이 아닌 첫 글자로 커서를 옮기고, n이 명시되지 않은 겨우는 파일의 마지막 라인의 공백이 아닌 첫 글자로 옮긴다. |
→ vi 명령어의 라인 또는 화면 단위의 커서 이동 명령어
2. 편집 명령어
키 |
내용 |
a |
커서의 우측에 ESC를 입력할 때까지 입력한 모든 글자를 추가한다(Append). |
A |
현재 라인의 맨 끝에 ESC를 입력할 때까지 입력한 모든 글자를 추가한다. 숫자 n을 명시하면 n번 반복해서 입력한다(Append) |
I |
현재 라인의 공백이 아닌 첫 글자 앞에서 ESC를 입력할 때까지 입력한 모든 글자를 추가한다(Insert). |
o |
현재 라인 밑에 새로운 라인을 열고 ESC를 입력할 때까지 입력한 모든 글자를 추가한다(Open). |
O |
현재 라인 위에 새로운 라인을 열고 ESC를 입력할 때까지 입력한 모든 글자를 추가한다(Open). |
X |
현재 커서의 왼쪽 글자를 지운다. |
dpos |
현재 커서부터 pos로 명시한 이동 명령어로 명시한 곳까지 글자를 지운다. 이동 명령어는 어떠한 것이 와도 상관없이, 그 명령어의 의미가 나타는 곳까지 글자를 지운다. 따라서 조합할 수 있는 명령어는 dh,dj,dk,dl,dw,db,de,dW,dB,dE,dH,dM,dL,d0,d^,d$,d-d,+,d_,d| 등 헤아릴 수 없이 많은 명령어를 만들 수 있다(Delete). |
dd |
현재 커서가 위치한 라인을 지운다(Delete). |
D |
현재 커서가 위치한 곳부터 라인의 끝까지 지운다. 앞에 숫자 n이 명시된 경우 현재 라인의 끝까지 지우고 추가로 커서 아래에 있는 n-1 개의 라인을 지워서 레지스터에 넣는다(Delete). |
cpos |
현재 커서부터 pos로 명시한 이동 명령어로 명시한 곳까지 글자를 다른 글자로 대체한다. 이동 명령어는 어떠한 명령어가 와도 상관없이 그 명령어가 나태는 곳까지의 글자를 없애서 레지스터에 넣고 ESC을 입력할 때까지 입력한 모든 내용으로 대체한다. 따라서 조합할 수 있는 명령어는 ch,cj,ck,cl,cw,db,ce,cW,cB,cE,cH,cM,cL,c0,c^,c$,c-,c+c_,c| 등 헤아릴 수 없이 많은 명령어를 만들 수 있다(Change). |
cc |
현재 커서가 있는 라인 전체를 ESC를 입력할 때까지 입력한 다른 글자로 대체한다. 다른 글자로 대체된 원래의 글자들은 레지스터에 저장된다(Change). |
C |
현재 커서가 위치한 곳부터 라인의 끝까지를 ESC를 입력할 때까지 입력한 글자로 대체한다. |
s |
현재 커서가 위치한 한 글자를 ESC를 입력할 때까지 입력한 다음 글자로 대체한다(Substitute). |
S |
현재 커서가 있는 라인 전체를 ESC를 입력할 때까지 입력한 다음 글자로 대체 한다(Subsutitute). |
r |
커서가 위치한 곳의 글자를 다른 하나의 글자로 대체한다(Replace). |
R |
커서가 위치한 곳부터 우측으로 가면서 글자를 대체하는데 ESC를 누를때까지 입력한 개수만큼 기존의 글자가 새로운 글자로 대체된다(Replace). |
~ |
커서에 있는 글자의 대소문자를 서로 바꾼다. 즉 ~를 누를 때마다 커서의 우측으로 옮기면서 커서에 있는 글자가 소문자일 경우는 대문자로, 대문자인 경우는 소문자로 바꾼다. |
. |
가장 마지막에 실행한 편집 명령어를 똑같이 반복한다. |
J |
커서가 있는 라인부터 아래 하나의 라인으로 연결한다. 이때 연결되는 각 라인은 공백으로 띄워진다(Join). |
ypos |
커서가 있는 위치부터 pos로 명시한 이동 명령어가 나타내는 곳까지 복사해서 레지스터에 저장한다. 레지스터의 이름을 명시하지 않으면 임시 레지스터에 저장된다(Yank). |
yy Y |
커서가 있는 라인의 데이터를 복사한다. |
p |
마지막으로 지우거나 복사한 데이터를 읽어서 커서의 우측에 데이터를 추가한다(Paste). |
P |
마지막으로 지우거나 복사한 데이터를 읽어서 커서의 좌측에 데이터를 추가한다(Paste). |
u |
마지막에 실행한 편집 명령어를 하나를 취소한다(Undo). |
U |
현재 커서가 있는 라인이 변경이 된 후에 이동을 하지 않았다면 현재 라인을 원상 복구한다(Undo). |
3. 화면을 움직이는 명령어
키 |
내용 |
Ctrl+e |
한 라인을 위로 올린다. |
Ctrl+d |
한 라인을 위로 올린다(Downward). |
Ctrl+f |
한 페이지를 위로 올린다(Forward). |
Ctrl+y |
한 라인을 아래로 내린다. |
Ctrl+u |
한 라인을 아래로 내린다(Upward). |
Ctrl+b |
한 페이지를 아래로 내린다(Backward). |
4. 검색 명령어
키 |
내용 |
/pattern |
/ 다음에 찾고자 하는 글자의 정규식을 사용해서 패턴 형태로 입력하면 커서의 우측 아래쪽 방향으로 패턴을 찾는다. |
?pattern |
? 다음에 찾고자 하는 글자의 정규식을 사용해서 패턴 형태로 입력하면 커서의 좌측 위쪽 방향으로 패턴을 찾는다. |
n |
가장 마지막으로 실행한 검색 명령어를 똑같은 방향으로 실행한다. 마지막 검색이 우측일 경우(/를 사용한 경우)는 우측으로, 좌측일 경우(?를 사용한 경우)는 좌측으로 패턴을 찾는다(Next). |
N |
가장 마지막으로 실행한 검색 명령어를 반대 방향으로 실행한다. 마지막 검색이 우측일 경우(/를 사용한 경우)는 좌측으로, 좌측일 경우(?를 사용한 경우)는 우측으로 패턴을 찾는다(Next). |
5. 기타 명령어
키 |
내용 |
:q! |
현재 편집하는 파일을 저장하지 않고 vi 에디터를 종료한다. |
:e filename |
filename 파일을 읽어서 편집한다. |
:r filename |
현재 편집하는 파일 내부에 filename 을 읽어들여 첨가한다. |
vi 기타 명령어
vi 설정 명령어
밑의 명령어를 vi 에디터를 실행할 때마다 적어넣기 불편하므로 vi 에디터의 설정을 저장한 파일
즉, ~/.exrc 파일에 자신에게 적합한 설정 사항을 넣어 두면 매번 따로 설정하는 불편함이 사라진다.
키 |
내용 |
:set nu |
각 라인 앞에 라인 번호를 붙인다(NUmber). |
:set nonu |
각 라인 앞에 라인 번호를 붙이지 않는다(NO NUmber). |
:set ic |
패턴을 찾을 때 대소문자를 구별하지 않는다(Ignore Case). |
:set noic |
패턴을 찾을 때 대소문자를 구별한다(NO Ignore Case). |
:set showmode |
현재 vi 에디터의 상태를 나타낸다. |
:set noshowmode |
현재 vi 에디터의 상태를 전혀 나타내지 않는다. |
:set ai |
자동 들여쓰기를 한다(Auto Indent). |
:set ts=n |
탭의 크기를 n으로 정한다(Tab Stop). |
'저장용' 카테고리의 다른 글
mount.. (0) | 2009.03.26 |
---|---|
crond 를 이용해서 백업하기 (0) | 2009.03.26 |
samba 설치 , 실행 (0) | 2009.03.23 |
쉘 프롬프트에서 질의 실행하기. (0) | 2009.03.20 |
mysql [12.5.1.3. GRANT Syntax] (0) | 2009.03.20 |
다음의 rpm을 설치해준다.
{
samba-swat-3.0.23c-2
samba-client-3.0.23c-2
samba-3.0.23c-2
samba-common-3.0.23c-2
system-config-samba-1.2.39-1.el5
}
(설치는 rpm -ivh rpm_name )
삼바 서버 구동은 아래와 같이한다.
# /etc/init.d/smb start
삼바 서버를 중지는 아래와 같이한다.
# /etc/init.d/smb stop
사용자 추가
smbadduser admin:admin
Adding: admin to /etc/samba/smbpasswd
Added user admin.
----------------------------------------------------------
ENTER password for admin
New SMB password:
Retype new SMB password:
Password changed for user admin.
Password changed for user admin.
그 이후 /etc/samba/smb.conf 환경 설정 파일에서 설정.
{
[global]
workgroup = workgroup
server string = samba
log file = /var/log/samba/%m.log
security = share
encrypt passwords = yes
smb passwd file = /etc/samba/smbpasswd
client code page = 949
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
Hosts allow = 192.168.2.
[homes]
comment = home directory
browseable = no
read only = no
[public]
comment = public
path = /public
public = yes
writable = yes
printable = no
write list = @staff
#guest = ok ← 게스트 접속(인증이 필요없음) 가능
}
※윈도우에서 삼바서버가 설치되어있는 곳으로 접속을 시도-
연결이 되고 파일의 다운로드가 가능하면 성공
윈도우에 있는 공유폴더를 리눅스에 마운트 시키자-
mount -t cifs //192.168.2.42/backup /mnt/backup
(mount -t cifs //윈도우IP/공유폴더 /mnt/마운트폴더)
마운트 한 이후에 ls mnt/backup 확인
'저장용' 카테고리의 다른 글
crond 를 이용해서 백업하기 (0) | 2009.03.26 |
---|---|
vi 명령어 (0) | 2009.03.23 |
쉘 프롬프트에서 질의 실행하기. (0) | 2009.03.20 |
mysql [12.5.1.3. GRANT Syntax] (0) | 2009.03.20 |
mysqldump 사용법 (0) | 2009.03.19 |
'저장용' 카테고리의 다른 글
vi 명령어 (0) | 2009.03.23 |
---|---|
samba 설치 , 실행 (0) | 2009.03.23 |
mysql [12.5.1.3. GRANT Syntax] (0) | 2009.03.20 |
mysqldump 사용법 (0) | 2009.03.19 |
mysqldump 명령어 (0) | 2009.03.19 |
GRANTpriv_type
[(column_list
)] [,priv_type
[(column_list
)]] ... ON [object_type
]priv_level
TOuser
[IDENTIFIED BY [PASSWORD] 'password
'] [,user
[IDENTIFIED BY [PASSWORD] 'password
']] ... [REQUIRE {NONE |ssl_option
[[AND]ssl_option
] ...}] [WITHwith_option
[with_option
] ...]object_type
: TABLE | FUNCTION | PROCEDUREpriv_level
: * | *.* |db_name
.* |db_name.tbl_name
|tbl_name
|db_name
.routine_name
with_option
: GRANT OPTION | MAX_QUERIES_PER_HOURcount
| MAX_UPDATES_PER_HOURcount
| MAX_CONNECTIONS_PER_HOURcount
| MAX_USER_CONNECTIONScount
ssl_option
: SSL | X509 | CIPHER 'cipher
' | ISSUER 'issuer
' | SUBJECT 'subject
'
The GRANT
statement enables system administrators to create MySQL user accounts and to grant rights to accounts. To use GRANT
, you must have the GRANT OPTION
privilege, and you must have the privileges that you are granting. The REVOKE
statement is related and enables administrators to remove account privileges. To determine what privileges an account has, use SHOW GRANTS
. See Section 12.5.1.5, “REVOKE
Syntax”, and Section 12.5.5.17, “SHOW GRANTS
Syntax”.
MySQL Enterprise. For automated notification of users with inappropriate privileges, subscribe to the MySQL Enterprise Monitor. For more information, see http://www.mysql.com/products/enterprise/advisors.html.
The following table summarizes the allowable priv_type
privilege types that can be specified for the GRANT
and REVOKE
statements. For additional information about these privileges, see Section 5.4.1, “Privileges Provided by MySQL”.
Privilege | Meaning |
ALL [PRIVILEGES] |
Grant all privileges at specified access level except GRANT OPTION |
ALTER |
Enable use of ALTER TABLE |
ALTER ROUTINE |
Enable stored routines to be altered or dropped |
CREATE |
Enable database and table creation |
CREATE ROUTINE |
Enable stored routine creation |
CREATE TEMPORARY TABLES |
Enable use of CREATE TEMPORARY TABLE |
CREATE USER |
Enable use of CREATE USER , DROP USER , RENAME USER , and REVOKE ALL PRIVILEGES |
CREATE VIEW |
Enable views to be created or altered |
DELETE |
Enable use of DELETE |
DROP |
Enable databases, tables, and views to be dropped |
EXECUTE |
Enable the user to execute stored routines |
FILE |
Enable the user to cause the server to read or write files |
GRANT OPTION |
Enable privileges to be granted to or removed from other accounts |
INDEX |
Enable indexes to be created or dropped |
INSERT |
Enable use of INSERT |
LOCK TABLES |
Enable use of LOCK TABLES on tables for which you have the SELECT privilege |
PROCESS |
Enable the user to see all processes with SHOW PROCESSLIST |
REFERENCES |
Not implemented |
RELOAD |
Enable use of FLUSH operations |
REPLICATION CLIENT |
Enable the user to ask where master or slave servers are |
REPLICATION SLAVE |
Enable replication slaves to read binary log events from the master |
SELECT |
Enable use of SELECT |
SHOW DATABASES |
Enable SHOW DATABASES to show all databases |
SHOW VIEW |
Enable use of SHOW CREATE VIEW |
SHUTDOWN |
Enable use of mysqladmin shutdown |
SUPER |
Enable use of CHANGE MASTER TO , KILL , PURGE BINARY LOGS , and SET GLOBAL statements, the mysqladmin debug command; allows you to connect (once) even if max_connections is reached |
UPDATE |
Enable use of UPDATE |
USAGE |
Synonym for “no privileges” |
The EXECUTE
privilege is not operational until MySQL 5.0.3. CREATE VIEW
and SHOW VIEW
were added in MySQL 5.0.1. CREATE USER
, CREATE ROUTINE
, and ALTER ROUTINE
were added in MySQL 5.0.3.
USAGE
can be specified when you want to create a user that has no privileges, or to modify the REQUIRE
or WITH
clauses for an account without changing its existing privileges.
MySQL account information is stored in the tables of the mysql
database. This database and the access control system are discussed extensively in Chapter 5, MySQL Server Administration, which you should consult for additional details.
Important
Some releases of MySQL introduce changes to the structure of the grant tables to add new privileges or features. Whenever you update to a new version of MySQL, you should update your grant tables to make sure that they have the current structure so that you can take advantage of any new capabilities. See Section 4.4.9, “mysql_upgrade — Check Tables for MySQL Upgrade”.
If the grant tables hold privilege rows that contain mixed-case database or table names and the lower_case_table_names
system variable is set to a non-zero value, REVOKE
cannot be used to revoke these privileges. It will be necessary to manipulate the grant tables directly. (GRANT
will not create such rows when lower_case_table_names
is set, but such rows might have been created prior to setting the variable.)
Privileges can be granted at several levels, depending on the syntax used for the ON
clause. For REVOKE
, the same ON
syntax specifies which privileges to take away. The examples shown here include no IDENTIFIED BY '
clause for brevity, but you should include one if the account does not already exist to avoid creating an account with no password. password
'
Global privileges
Global privileges are administrative or apply to all databases on a given server. To assign global privileges, use ON *.*
syntax:
GRANT ALL ON *.* TO 'someuser'@'somehost'; GRANT SELECT, INSERT ON *.* TO 'someuser'@'somehost';
Privileges also are assigned at the global level if you use ON *
syntax and you have not selected a default database.
The CREATE USER
, FILE
, PROCESS
, RELOAD
, REPLICATION CLIENT
, REPLICATION SLAVE
, SHOW DATABASES
, SHUTDOWN
, and SUPER
privileges are administrative and can only be granted globally.
Other privileges can be granted globally or at more specific levels.
Global privileges are stored in the mysql.user
table.
Database privileges
Database privileges apply to all objects in a given database. To assign database-level privileges, use ON
syntax: db_name
.*
GRANT ALL ON mydb.* TO 'someuser'@'somehost'; GRANT SELECT, INSERT ON mydb.* TO 'someuser'@'somehost';
Privileges also are assigned at the database level if you use ON *
syntax and you have selected a default database.
The CREATE
, DROP
, and GRANT OPTION
privileges can be specified at the database level. Table or routine privileges also can be specified at the database level, in which case they apply to all tables or routines in the database.
Database privileges are stored in the mysql.db
and mysql.host
tables. GRANT
and REVOKE
affect the db
table, but not the host
table, which is rarely used.
Table privileges
Table privileges apply to all columns in a given table. To assign table-level privileges, use ON
syntax: db_name.tbl_name
GRANT ALL ON mydb.mytbl TO 'someuser'@'somehost'; GRANT SELECT, INSERT ON mydb.mytbl TO 'someuser'@'somehost';
If you specify tbl_name
rather than db_name.tbl_name
, the statement applies to tbl_name
in the default database. An error occurs if there is no default database.
The allowable priv_type
values for a table are ALTER
, CREATE VIEW
, CREATE
, DELETE
, DROP
, GRANT OPTION
, INDEX
, INSERT
, SELECT
, SHOW VIEW
, and UPDATE
.
Table privileges are stored in the mysql.tables_priv
table.
Column privileges
Column privileges apply to single columns in a given table. Each privilege to be granted at the column level must be followed by the column or columns, enclosed within parentheses.
GRANT SELECT (col1), INSERT (col1,col2) ON mydb.mytbl TO 'someuser'@'somehost';
The allowable priv_type
values for a column (that is, when you use a column_list
clause) are INSERT
, SELECT
, and UPDATE
.
Column privileges are stored in the mysql.columns_priv
table.
Routine privileges
The ALTER ROUTINE
, CREATE ROUTINE
, EXECUTE
, and GRANT OPTION
privileges apply to stored routines (procedures and functions). They can be granted at the global and database levels. Except for CREATE ROUTINE
, these privileges can be granted at the routine level for individual routines.
GRANT CREATE ROUTINE ON mydb.* TO 'someuser'@'somehost'; GRANT EXECUTE ON PROCEDURE mydb.myproc TO 'someuser'@'somehost';
The allowable priv_type
values at the routine level are ALTER ROUTINE
, EXECUTE
, and GRANT OPTION
. CREATE ROUTINE
is not a routine-level privilege because you must have this privilege to create a routine in the first place.
Routine-level privileges are stored in the mysql.procs_priv
table.
For the global, database, table, and routine levels, GRANT ALL
assigns only the privileges that exist at the level you are granting. For example, GRANT ALL ON
is a database-level statement, so it does not grant any global-only privileges such as db_name
.*FILE
.
The object_type
clause was added in MySQL 5.0.6. If present, it should be specified as TABLE
, FUNCTION
, or PROCEDURE
when the following object is a table, a stored function, or a stored procedure.
The privileges for a database, table, column, or routine are formed additively as the logical OR
of the privileges at each of the privilege levels. For example, if a user has a global SELECT
privilege, the privilege cannot be denied by an absence of the privilege at the database, table, or column level. Details of the privilege-checking procedure are presented in Section 5.4.4, “Access Control, Stage 2: Request Verification”.
MySQL enables you to grant privileges even on database objects that do not exist. In such cases, the privileges to be granted must include the CREATE
privilege. This behavior is by design, and is intended to enable the database administrator to prepare user accounts and privileges for database objects that are to be created at a later time.
Important
MySQL does not automatically revoke any privileges when you drop a database or table. However, if you drop a routine, any routine-level privileges granted for that routine are revoked.
The user
value indicates which MySQL account to grant the privileges to. To accommodate granting rights to users from arbitrary hosts, MySQL supports specifying the user
value in the form
. If a user_name
@host_name
user_name
or host_name
value is legal as an unquoted identifier, you need not quote it. However, quotes are necessary to specify a user_name
string containing special characters (such as “-
”), or a host_name
string containing special characters or wildcard characters (such as “%
”); for example, 'test-user'@'test-hostname'
. Quote the user name and host name separately.
You can specify wildcards in the host name. For example,
applies to user_name
@'%.loc.gov'user_name
for any host in the loc.gov
domain, and
applies to user_name
@'144.155.166.%'user_name
for any host in the 144.155.166
class C subnet.
The simple form user_name
is a synonym for
. user_name
@'%'
MySQL does not support wildcards in user names. Anonymous users are created by specifying a user with an empty name with the GRANT
statement:
GRANT ALL ON test.* TO ''@'localhost' ...
In this case, any user who connects from the local host with the correct password for the anonymous user will be allowed access, with the privileges associated with the anonymous-user account.
To specify quoted values, quote database, table, column, and routine names as identifiers, using backticks (“`
”). Quote host names and user names as identifiers or as strings, using either backticks or single quotes (“'
”). Quote passwords as strings, using single quotes.
The “_
” and “%
” wildcards are allowed when specifying database names in GRANT
statements that grant privileges at the global or database levels. This means, for example, that if you want to use a “_
” character as part of a database name, you should specify it as “\_
” in the GRANT
statement, to prevent the user from being able to access additional databases matching the wildcard pattern; for example, GRANT ... ON `foo\_bar`.* TO ...
.
Warning
If you allow anonymous users to connect to the MySQL server, you should also grant privileges to all local users as
. Otherwise, the anonymous user account for user_name
@localhostlocalhost
in the mysql.user
table (created during MySQL installation) is used when named users try to log in to the MySQL server from the local machine. For details, see Section 5.4.3, “Access Control, Stage 1: Connection Verification”.
You can determine whether the preceding warning applies to you by executing the following query, which lists any anonymous users:
SELECT Host, User FROM mysql.user WHERE User='';
To avoid the problem just described, delete the local anonymous user account using this statement:
DROP USER ''@'localhost';
GRANT
supports host names up to 60 characters long. Database, table, column, and routine names can be up to 64 characters. User names can be up to 16 characters.
Warning
The allowable length for user names cannot be changed by altering the mysql.user
table. Attempting to do so results in unpredictable behavior which may even make it impossible for users to log in to the MySQL server. You should never alter any of the tables in the mysql
database in any manner whatsoever except by means of the procedure prescribed by MySQL AB that is described in Section 4.4.9, “mysql_upgrade — Check Tables for MySQL Upgrade”.
If the NO_AUTO_CREATE_USER
SQL mode is not enabled and the account named in a GRANT
statement does not exist in the mysql.user
table, GRANT
creates it. If you specify no IDENTIFIED BY
clause or provide an empty password, the user has no password. This is very insecure.
If NO_AUTO_CREATE_USER
is enabled and the account does not exist, GRANT
fails and does not create the account unless the IDENTIFIED BY
clause is given to provide a non-empty password.
When the IDENTIFIED BY
clause is present and you have global grant privileges, the password becomes the new password for the account, even if the account exists and already has a password.
MySQL Enterprise. The MySQL Enterprise Monitor specifically guards against user accounts with no passwords. To find out more, see http://www.mysql.com/products/enterprise/advisors.html.
REVOKE
does not remove mysql.user
table entries; you must do that using DROP USER
or DELETE
.
Passwords can also be set with the SET PASSWORD
statement. See Section 12.5.1.6, “SET PASSWORD
Syntax”.
In the IDENTIFIED BY
clause, the password should be given as the literal password value. It is unnecessary to use the PASSWORD()
function as it is for the SET PASSWORD
statement. For example:
GRANT ... IDENTIFIED BY 'mypass';
If you do not want to send the password in clear text and you know the hashed value that PASSWORD()
would return for the password, you can specify the hashed value preceded by the keyword PASSWORD
:
GRANT ... IDENTIFIED BY PASSWORD '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4';
The WITH
clause is used for several purposes:
-
To enable a user to grant privileges to other users
-
To specify resource-use limitations on a user
-
To specify whether and how a user must use secure connections to the server
The WITH GRANT OPTION
clause gives the user the ability to give to other users any privileges the user has at the specified privilege level. You should be careful to whom you give the GRANT OPTION
privilege, because two users with different privileges may be able to combine privileges!
You cannot grant another user a privilege which you yourself do not have; the GRANT OPTION
privilege enables you to assign only those privileges which you yourself possess.
Be aware that when you grant a user the GRANT OPTION
privilege at a particular privilege level, any privileges the user possesses (or may be given in the future) at that level can also be granted by that user to other users. Suppose that you grant a user the INSERT
privilege on a database. If you then grant the SELECT
privilege on the database and specify WITH GRANT OPTION
, that user can give to other users not only the SELECT
privilege, but also INSERT
. If you then grant the UPDATE
privilege to the user on the database, the user can grant INSERT
, SELECT
, and UPDATE
.
For a non-administrative user, you should not grant the ALTER
privilege globally or for the mysql
database. If you do that, the user can try to subvert the privilege system by renaming tables!
For additional information about security risks associated with particular privileges, see Section 5.4.1, “Privileges Provided by MySQL”.
The MAX_QUERIES_PER_HOUR
, count
MAX_UPDATES_PER_HOUR
, and count
MAX_CONNECTIONS_PER_HOUR
options limit the number of queries, updates, and logins a user can perform during any given one-hour period. (Queries for which results are served from the query cache do not count against the count
MAX_QUERIES_PER_HOUR
limit.) If count
is 0
(the default), this means that there is no limitation for that user.
The MAX_USER_CONNECTIONS
option, implemented in MySQL 5.0.3, limits the maximum number of simultaneous connections that the account can make. If count
count
is 0
(the default), the max_user_connections
system variable determines the number of simultaneous connections for the account.
To specify any of these resource-limit options for an existing user without affecting existing privileges, use GRANT USAGE ON *.* ... WITH MAX_...
.
For more information on restricting resources, see Section 5.5.4, “Limiting Account Resources”.
MySQL can check X509 certificate attributes in addition to the usual authentication that is based on the user name and password. To specify SSL-related options for a MySQL account, use the REQUIRE
clause of the GRANT
statement. (For background information on the use of SSL with MySQL, see Section 5.5.7, “Using SSL for Secure Connections”.)
There are a number of different possibilities for limiting connection types for a given account:
-
REQUIRE NONE
indicates that the account has no SSL or X509 requirements. This is the default if no SSL-relatedREQUIRE
options are specified. Unencrypted connections are allowed if the user name and password are valid. However, encrypted connections can also be used, at the client's option, if the client has the proper certificate and key files. That is, the client need not specify any SSL command options, in which case the connection will be unencrypted. To use an encrypted connection, the client must specify either the--ssl-ca
option, or all three of the--ssl-ca
,--ssl-key
, and--ssl-cert
options. -
The
REQUIRE SSL
option tells the server to allow only SSL-encrypted connections for the account.GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost' IDENTIFIED BY 'goodsecret' REQUIRE SSL;
To connect, the client must specify the
--ssl-ca
option, and may additionally specify the--ssl-key
and--ssl-cert
options. -
REQUIRE X509
means that the client must have a valid certificate but that the exact certificate, issuer, and subject do not matter. The only requirement is that it should be possible to verify its signature with one of the CA certificates.GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost' IDENTIFIED BY 'goodsecret' REQUIRE X509;
To connect, the client must specify the
--ssl-ca
,--ssl-key
, and--ssl-cert
options. This is also true forISSUER
andSUBJECT
because thoseREQUIRE
options implyX509
. -
REQUIRE ISSUER '
places the restriction on connection attempts that the client must present a valid X509 certificate issued by CAissuer
''
. If the client presents a certificate that is valid but has a different issuer, the server rejects the connection. Use of X509 certificates always implies encryption, so theissuer
'SSL
option is unnecessary in this case.GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost' IDENTIFIED BY 'goodsecret' REQUIRE ISSUER '/C=FI/ST=Some-State/L=Helsinki/ O=MySQL Finland AB/CN=Tonu Samuel/Email=tonu@example.com';
Note that the
'
value should be entered as a single string.issuer
' -
REQUIRE SUBJECT '
places the restriction on connection attempts that the client must present a valid X509 certificate containing the subjectsubject
'subject
. If the client presents a certificate that is valid but has a different subject, the server rejects the connection.GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost' IDENTIFIED BY 'goodsecret' REQUIRE SUBJECT '/C=EE/ST=Some-State/L=Tallinn/ O=MySQL demo client certificate/ CN=Tonu Samuel/Email=tonu@example.com';
Note that the
'
value should be entered as a single string.subject
' -
REQUIRE CIPHER '
is needed to ensure that ciphers and key lengths of sufficient strength are used. SSL itself can be weak if old algorithms using short encryption keys are used. Using this option, you can ask that a specific cipher method is used to allow a connection.cipher
'GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost' IDENTIFIED BY 'goodsecret' REQUIRE CIPHER 'EDH-RSA-DES-CBC3-SHA';
The SUBJECT
, ISSUER
, and CIPHER
options can be combined in the REQUIRE
clause like this:
GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost' IDENTIFIED BY 'goodsecret' REQUIRE SUBJECT '/C=EE/ST=Some-State/L=Tallinn/ O=MySQL demo client certificate/ CN=Tonu Samuel/Email=tonu@example.com' AND ISSUER '/C=FI/ST=Some-State/L=Helsinki/ O=MySQL Finland AB/CN=Tonu Samuel/Email=tonu@example.com' AND CIPHER 'EDH-RSA-DES-CBC3-SHA';
The order of the options does not matter, but no option can be specified twice. The AND
keyword is optional between REQUIRE
options.
If you are using table, column, or routine privileges for even one user, the server examines table, column, and routine privileges for all users and this slows down MySQL a bit. Similarly, if you limit the number of queries, updates, or connections for any users, the server must monitor these values.
The biggest differences between the standard SQL and MySQL versions of GRANT
are:
-
In MySQL, privileges are associated with the combination of a host name and user name and not with only a user name.
-
Standard SQL does not have global or database-level privileges, nor does it support all the privilege types that MySQL supports.
-
MySQL does not support the standard SQL
UNDER
privilege, and does not support theTRIGGER
privilege until MySQL 5.1.6. -
Standard SQL privileges are structured in a hierarchical manner. If you remove a user, all privileges the user has been granted are revoked. This is also true in MySQL 5.0.2 and up if you use
DROP USER
. Before 5.0.2, the granted privileges are not automatically revoked; you must revoke them yourself. See Section 12.5.1.2, “DROP USER
Syntax”. -
In standard SQL, when you drop a table, all privileges for the table are revoked. In standard SQL, when you revoke a privilege, all privileges that were granted based on that privilege are also revoked. In MySQL, privileges can be dropped only with explicit
REVOKE
statements or by manipulating values stored in the MySQL grant tables. -
In MySQL, it is possible to have the
INSERT
privilege for only some of the columns in a table. In this case, you can still executeINSERT
statements on the table, provided that you omit those columns for which you do not have theINSERT
privilege. The omitted columns are set to their implicit default values if strict SQL mode is not enabled. In strict mode, the statement is rejected if any of the omitted columns have no default value. (Standard SQL requires you to have theINSERT
privilege on all columns.) Section 5.1.7, “Server SQL Modes”, discusses strict mode. Section 10.1.4, “Data Type Default Values”, discusses implicit default values.
'저장용' 카테고리의 다른 글
samba 설치 , 실행 (0) | 2009.03.23 |
---|---|
쉘 프롬프트에서 질의 실행하기. (0) | 2009.03.20 |
mysqldump 사용법 (0) | 2009.03.19 |
mysqldump 명령어 (0) | 2009.03.19 |
mysql resplication (0) | 2009.03.19 |
mysqldump 를 통해 백업 받는 방법은 아래와 같다.
1. 명령어
: mysqldump [OPTIONS] databases [tables]
: mysqldump [OPTIONS] --databases [OPTIONS] DB1
: mysqldump [OPTIONS] --all-databases [OPTIONS]
2. mysqldump 사용방법
- 전체 데이타베이스를 백업
: mysqldump -u root -p -A > all.sql
-> 전체 데이타베이스를 all.sql 이란 파일명으로 백업
전체 데이터베이스에 대한 생성 및 테이블 생성, 데이터 생성 스크립트로 생성
- 한개의 데이타베이스만 백업
: mysqldump -u root -p --databases test_db > test_db.sql
-> test_db.sql 이라는 파일명으로 백업받으며, 전체가 아닌 test_db 라는 데이터베이스
에 대해 생성, 데이터 생성 스크립트로 구성된다.
- 두개 이상의 데이터 베이스 백업
: mysqldump -u root -p --databases test_db1 test_db2 > test_db.sql
-> test_db1, test_db2 의 데이터 베이스를 백업 받으며, 그 이상의 데이터 베이스를
백업 받고자 한다면, test_db2 뒤로 추가해준다.
- 데이타베이스의 특정 테이블만 백업
: mysqldump -u root -p test_db test > test.sql
-> test_db 내에 존재하는 test 테이블에 대한 생성, 데이터 입력 스크립트를 백업
단, 테이블 백업은 데이터 베이스 생성 스크립트가 존재 하지 않는다.
{
root]mysql -uroot -p 넣고싶은DB이름 < 덤프된이름.sql
덤프로 백업한 것을 원하는 디비에 넣는다.
}
'저장용' 카테고리의 다른 글
쉘 프롬프트에서 질의 실행하기. (0) | 2009.03.20 |
---|---|
mysql [12.5.1.3. GRANT Syntax] (0) | 2009.03.20 |
mysqldump 명령어 (0) | 2009.03.19 |
mysql resplication (0) | 2009.03.19 |
mysql 명령어 (0) | 2009.03.17 |