職案人

求職・歴史・仏教などについて掲載するつもりだが、自分の思いつきが多いブログだよ。適当に付き合って下さい。

データベースの作成、ユーザの追加と権限の設定

2016年04月15日 | mySQL
データベースの作成、ユーザの追加と権限の設定



■データベースにユーザーを追加し、権限を設定するには
1)phpMyAdminの場合
IT学習サイトのユーザーの作成を参考

2)コマンドプロンプトの場合
本日も乙」サイトを参照の事

grant 権限 on データベース名.* to 'ユーザー名'@'localhost' identified by 'パスワード';

【例】
データベース:testdatabase
ユーザー:testuser
パスワード:password
権限:all

コマンド
mysql>grant all on testdatabase.* TO 'testuser@localhost' identified by 'password';




 
1)データ権限
・SELECT・・・データの表示
・INSERT・・・データの挿入
・UPDATE・・・データの修正
・DELETE・・・データの削除

2)構造権限
作成するユーザーに対して、権限を設定します。
•all privileges ・・・ GRANT(権限の付与)以外の権限を付与
•alter ・・・ テーブル変更
•create ・・・ テーブル作成
•drop ・・・ テーブル削除
•index ・・・ インデックス作成、削除
•select ・・・ select文
•insert ・・・ insert文
•update ・・・ update文
•delete ・・・ delete文

3)管理権限
作成するユーザーに権限が付与される対象を設定します。
•グローバル権限 ・・・ すべてのデータベースが対象
•データベース ・・・ 指定したデータベースが対象
•テーブル ・・・ 指定したデータベースのテーブルが対象

■ユーザとその権限の確認方法
mysql> show grant for testuser@localhost;


■ユーザーの削除方法
mysql> revoke all privileges on *.* from testuser@localhost;


■ユーザでアクセス
C:\Users\hnaka>mysql -u testuser -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 48
Server version: 5.6.20

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
■コマンドプロンプで文字化けする時は
mysql>set nemes cp932;
データーベースのテーブル表示の日本語が文字化けしない

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする