ホームページ  >  記事  >  データベース  >  MySQL認可コマンドgrantの使い方を詳しく解説

MySQL認可コマンドgrantの使い方を詳しく解説

怪我咯
怪我咯オリジナル
2017-06-23 13:43:563336ブラウズ

この記事の例は、MySQL 5.0 以降で実行されます。

MySQL ユーザー権限を付与するコマンドの簡単な形式は次のように要約できます:

grant 権限 on データベースオブジェクト to ユーザー

1. 通常の権限を付与データユーザー、クエリ、挿入、データベース内のすべてのテーブル データを更新および削除する権利。

grant select on testdb.* to common_user@'%'
grant insert on testdb.* to common_user@ '%'
grant testdb.* to common_user@'%'grant
削除 上で testdb.* common_user@'%'
または、代わりに MySQL コマンドを使用します:

grant
select, insert 更新削除 on testdb .* to common_user@'%'

2. データベース開発者に権限を与え、テーブル、インデックス、ビュー、ストアド プロシージャ、関数を作成します。 。 。およびその他の権限。

MySQL データテーブル構造を作成、変更、削除する権限を付与します。

grant create testdb.* to開発者@'192.168.0.%';
grant alter テストデータベース上* to開発者@'192.168.0.%';grant
ドロップontestdb.*to開発者@'192.168.0.%' ;
grantは、MySQLの外部キー権限を操作します。

grant
リファレンス on testdb.* to開発者@'192.168.0.%'; MySQL 一時テーブルを操作する権限を付与します。

grant
create 一時テーブルon testdb.* to開発者@'192.168.0.%'; MySQL インデックスを操作する権限を付与します。

grant
index on testdb.* to開発者@'192.168.0.%';

MySQL ビューを操作し、ソース コードを表示する権限を付与します。

grant create view on testdb.* to開発者@'192.168.0.%';
grant show testdb を表示します。 * developer@'192.168.0.%' MySQL ストアド プロシージャと関数。
grant
create
ルーチン
on
testdb.
*
to
developer@
'
192.168.0.%
'
--

プロシージャステータスを表示できるようになりました

;
助成金 testdb.* のルーチンを変更 developer@'192.168.0.%' -- これで、プロシージャを削除できますgrantexecute
testdb.* 開発者@'192.168.0.%'
3. 一般の DBA に MySQL データベースを管理する権限を付与します。 grant all privileges
testdb
to
dba@
'
localhost
'
その中で、キーワードは「特権」 」は省略可能です。
4. 上級 DBA に MySQL のすべてのデータベースを管理する権限を付与します。
grant
all
on
*
.
*

to
dba@
'localhost'

5. MySQL の権限付与は複数のレベルで適用できます。

1. Grant は MySQL サーバー全体で機能します:

grant select on *.* to dba@localhost;すべての MySQL をクエリするデータベース内のテーブル。 grant
all on *.* to dba@localhost -- dba は MySQL 内のすべてのデータベースを管理できます 2. 付与は単一のデータベースで動作します: grant select
on
testdb.
*
to
dba
@localhost
;
--
dba は testdb 内のテーブルをクエリできます。

3. グラントは単一のデータテーブルで動作します: grant selectinsert 更新削除 testdb.orders to dba@localhost;

複数のテーブルをユーザーに許可する場合、上記のステートメントは次のようになります。複数回実行される。例: grant select(user_id,username) on smp.users to mo_user@'%'identified by ' 12 3345';
grant

select
on smp.mo_sms to mo_user@'%'が特定されましたby '123345';

4. 付与はテーブル内の列に作用します:

grant select(id, se, Rank) on testdb.apache_log to dba@localhost;

5. Grant はストアド プロシージャと関数で機能します:

grant execute on procedure testdb.pr_add to 'dba '@'ローカルホスト '
grant execute on function testdb.fn_add to 'dba'@'localhost' 6. MySQL ユーザー権限を表示します 現在のユーザー (自分) 権限を表示します。
補助金を表示する;
他の MySQL ユーザー権限を表示します:
showgrants
for
dba
@localhost
;

7. MySQL ユーザー権限に付与されている権限を取り消します。 Revokeには同様の構文が付与され、キーワードを「」から「」に置き換えるだけです。

取り消し

すべて
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 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。