>  기사  >  백엔드 개발  >  사용자 관리, 권한 및 설정 - mysql

사용자 관리, 권한 및 설정 - mysql

小云云
小云云원래의
2017-11-16 13:27:082227검색

MySQL은 세계에서 가장 인기 있는 데이터베이스 관리 시스템 중 하나입니다. 이 책은 간단한 데이터 검색에 대한 소개로 시작하여 조인, 하위 쿼리, 정규식 및 전체 텍스트 기반 검색, 저장 프로시저, 커서, 트리거, 테이블 제약 조건 등의 사용을 포함하여 점차 더 복잡한 내용으로 들어갑니다. 강조된 장을 통해 독자가 숙달해야 할 지식을 명확하고 체계적이며 간결하게 설명함으로써 즉각적으로, 무심코 실력을 향상시킬 수 있도록 해준다. 이 섹션에서는 주로 mysql 사용자 관리 및 권한 설정과 관련된 명령을 설명합니다.

사용자 관리

mysql>use mysql;

View

mysql>select host,user,password from user ;

Create

mysql>create user zx_root;

Modify

mysql>rename user feng to newuser; //mysql 5之后可以使用,之前需要使用update 更新user表

Delete

mysql>drop user newuser;   //mysql5之前删除用户时必须先使用revoke 删除用户权限,然后删除用户,mysql5之后drop 命令可以删除用户的同时删除用户的相关权限

비밀번호 변경

mysql>set password for zx_root =password('xxxxxx');
mysql>update  mysql.user  set  password=password('xxxx')  where user='otheruser'


사용자 권한 보기

mysql>show grants for zx_root;

권한 부여

mysql>grant select on dmc_db.*  to zx_root;

권한 재활용

mysql>revoke  select on dmc_db.*  from  zx_root;  //如果权限不存在会报错

위 명령도 여러 권한을 동시에 부여 및 철회할 수 있습니다. 쉼표를 사용하여 권한을 구분하세요.

mysql>grant select,update,delete  ,insert  on dmc_db.*  to  zx_root;

결과를 즉시 확인하려면

flush  privileges ;

명령어를 사용하세요. update

권한 설정 시 다음 정보를 제공해야 합니다.

1, 부여할 권한

2, 액세스가 부여된 데이터베이스 또는 테이블

3, 사용자 이름

grant 및 revoke는 여러 수준에서 액세스를 제어할 수 있습니다.

1, 전체 서버는 grant ALL 및 revoke ALL

2, 전체 데이터베이스, 데이터베이스에서 사용.*

3, 기능 테이블, 데이터베이스.테이블에서 사용

4, 특정 열

5, 특정 저장 프로시저

호스트 값의 의미 사용자 테이블의 열

% 모두 일치 호스트

localhost는 IP 주소로 구문 분석되지 않으며 UNIX 소켓을 통해 직접 연결됩니다.

127.0.0.1은 TCP/IP 프로토콜을 통해 연결되며 액세스만 가능합니다. 로컬로

::1 ::1 은 ipv6 과 호환되며, 이는 ipv4 127.0.0.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@'%'

9>.grant 데이터베이스 개발자는 테이블, 인덱스, 뷰, 저장 프로시저, 함수를 생성하세요. . . 및 기타 권한.

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.%';

10>.grant 일반 DBA는 MySQL 데이터베이스를 관리할 수 있는 권한을 가지고 있습니다.

grant all privileges on testdb to dba@'localhost'

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

11>.MySQL의 모든 데이터베이스를 관리할 수 있는 수석 DBA 권한을 부여합니다.

grant all on *.* to dba@'localhost'

12>.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;

4.

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'

참고: 권한을 수정한 후 서비스를 새로 고치거나 서비스를 다시 시작해야 합니다. FLUSH PRIVILEGES.

관련 권장 사항:

MySQL 쿼리 시간 관련 지식

PHP와 MySQL의 관계

PHP, Apache 및 mysql의 관계


위 내용은 사용자 관리, 권한 및 설정 - mysql의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.