MySQL에서 Grant 명령을 사용하는 방법

coldplay.xixi
풀어 주다: 2020-07-11 17:33:58
앞으로
2988명이 탐색했습니다.

이 문서의 예제는 MySQL 5.0 이상에서 실행됩니다.

MySQL 사용자 권한을 부여하는 간단한 명령 형식은 다음과 같이 요약할 수 있습니다.

grant 权限 on 数据库对象 to 用户
로그인 후 복사

관련 학습 권장 사항: mysql 비디오 튜토리얼

1. 일반 데이터 사용자 부여, 쿼리, 삽입, 업데이트, 삭제 데이터베이스의 모든 테이블 데이터 권한.

grant select on testdb.* to common_user@'%'
grant insert on testdb.* to common_user@'%'
grant update on testdb.* to common_user@'%'
grant delete on testdb.* to common_user@'%'
로그인 후 복사

또는 대신 MySQL 명령을 사용하세요.

grant select, insert, update, delete on testdb.* to common_user@'%'
로그인 후 복사

2. 데이터베이스 개발자에게 테이블, 인덱스, 뷰, 저장 프로시저 및 함수를 만들 수 있는 권한을 부여합니다. . . 및 기타 권한.

MySQL 데이터 테이블 구조를 생성, 수정, 삭제할 수 있는 권한을 부여합니다.

grant create on testdb.* to developer@'192.168.0.%';
grant alter on testdb.* to developer@'192.168.0.%';
grant drop on testdb.* to developer@'192.168.0.%';
로그인 후 복사

grant는 MySQL 외래 키 권한을 운영합니다.

grant references on testdb.* to developer@'192.168.0.%';
로그인 후 복사

MySQL 임시 테이블 운영 권한을 부여합니다.

grant create temporary tables on testdb.* to developer@'192.168.0.%';
로그인 후 복사

MySQL 인덱스 운영 권한을 부여하세요.

grant index on testdb.* to developer@'192.168.0.%';
로그인 후 복사

MySQL 뷰를 조작하고 소스 코드를 볼 수 있는 권한을 부여하세요.

grant create view on testdb.* to developer@'192.168.0.%';
grant show view on testdb.* to developer@'192.168.0.%';
로그인 후 복사

MySQL 저장 프로시저 및 기능을 작동할 수 있는 권한을 부여하세요.

grant create routine on testdb.* to developer@'192.168.0.%'; -- now, can show procedure status
grant alter routine on testdb.* to developer@'192.168.0.%'; -- now, you can drop a procedure
grant execute on testdb.* to developer@'192.168.0.%';
로그인 후 복사

3. 일반 DBA에게 MySQL 데이터베이스 관리 권한을 부여합니다.

grant all privileges on testdb to dba@'localhost'
로그인 후 복사

이중 '특권'이라는 키워드는 생략 가능합니다.

4. 선임 DBA에게 MySQL의 모든 데이터베이스를 관리할 수 있는 권한을 부여합니다.

grant all on *.* to dba@'localhost'
로그인 후 복사

5. MySQL 부여 권한은 여러 수준에서 적용될 수 있습니다.

1. Grant는 전체 MySQL 서버에서 작동합니다.

grant select on *.* to dba@localhost; -- dba 可以查询 MySQL 中所有数据库中的表。
grant all on *.* to dba@localhost; -- dba 可以管理 MySQL 中的所有数据库
로그인 후 복사

2. Grant는 단일 데이터베이스에서 작동합니다.

grant select on testdb.* to dba@localhost; -- dba 可以查询 testdb 中的表。
로그인 후 복사

3. Grant는 단일 데이터 테이블에서 작동합니다.

grant select, insert, update, delete on testdb.orders to dba@localhost;
로그인 후 복사

여기에서는 한 명의 사용자가 여러 테이블에 대해 권한을 부여받습니다. , 위의 문은 여러 번 실행될 수 있습니다. 예:

grant select(user_id,username) on smp.users to mo_user@'%' identified by '123345';
grant select on smp.mo_sms to mo_user@'%' identified by '123345';
로그인 후 복사

4. grant는 테이블의 열에 작용합니다.

grant select(id, se, rank) on testdb.apache_log to dba@localhost;
로그인 후 복사

5. grant는 저장 프로시저 및 함수에 작용합니다.

grant execute on procedure testdb.pr_add to 'dba'@'localhost'
grant execute on function testdb.fn_add to 'dba'@'localhost'
로그인 후 복사

6. 현재 사용자 보기(자신의) 권한 :

show grants;
로그인 후 복사

다른 MySQL 사용자 권한 보기:

show grants for dba@localhost;
로그인 후 복사

7. MySQL 사용자 권한에 부여된 권한을 취소합니다.

revoke에는 grant와 비슷한 구문이 있습니다. "to"를 "from"으로 바꾸세요.

grant all on *.* to dba@localhost;
revoke all on *.* from dba@localhost;
로그인 후 복사

8. MySQL 권한 부여 및 취소에 대한 참고 사항

1. 그런 다음 사용자가 권한을 적용하려면 MySQL 데이터베이스에 다시 연결해야 합니다.

2. 승인된 사용자가 다른 사용자에게 이러한 권한을 부여하려면 "grant option" 옵션이 필요합니다.

grant select on testdb.* to dba@localhost with grant option;
로그인 후 복사
이 기능은 일반적으로 사용되지 않습니다. 실제로 데이터베이스 권한은 DBA가 균일하게 관리하는 것이 가장 좋습니다.

위 내용은 MySQL에서 Grant 명령을 사용하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:jb51.net
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!