リレーショナル・データベースsql文

9974 ワード

リレーショナル・データベースsql文
リレーショナル・データベースmysql SQL文データベース管理操作.
1.ユーザーの作成(create user):構文(syntax):
     create user 'username'@'host' identified by 'password'
   (example):
     >create user 'shine'@'localhost' identified by '111111';  #      
     >create user 'shine'@'192.168.2.101' identified by '111111';  #   ip    :
     >create user 'shine'@'%' identified by '111111';   #       :
     >create user 'shine'@'%' identified by ''; #         
     >create user 'shine'@'%';  #  
     >create user shine; #  

2.授権(grant):構文(syntax):
     grant privilege1 [,privilege [, privilege] ...] on databaseName.tableName to username@hostname/IP identified by 'password' privilege: select, insert, update, delete, create, drop, index, alter, grant, references, reload, shutdown, process, file and so on fourteen privileges.

例(example):
>grant select, insert, update, delete, create, drop on demo.user to shine@192.168.2.101 identified by '111111';

アドレスが192.168.2.1101のshineユーザーにデータベースdemoテーブルuserにselect,insert,update,delete,create,drop権限を付与し、パスワード111111を使用する
>grant all privileges on demo.* to shine@192.168.2.101 identified by '111111';

アドレス192.168.2.1101のshineユーザにデータベースdemo上のすべてのテーブル上のすべての権限を付与し、パスワード111111を使用する.
>grant all privileges on *.* to shine@% identified by '111111'

shineユーザには、すべてのデータベース上のすべてのテーブル上のすべての権限が付与、パスワード111111が使用される.3.直接mysql.userテーブル挿入データ
>insert into user (host, user, password) values('%', 'shine', password('111111'));

4.システム権限の更新
>flush privileges;

5.mysqlユーザーパスワード方式の変更
  • mysqladmin:
  • を使用
         syntax:
          mysqladmin -u  username -p oldpassword password newpassword
          example:
          mysqladmin -u shine -p 111111 password 123456
  • userテーブルを変更するユーザkey:
  •      syntax:
          update mysql.user set password=password('newpasswd') where User="username" and Host="IP";
          example:
          update user set password=password('111111') where user='shine';
          flush privileges;
  • set password文を使用してパスワードを変更:
  •       syntax:
          set password for 'username'@'host' = password('newpassword');
          set password = password('newpassword') #        example: set password for 'shine'@'192.168.2.101'=password('111111');

    6.ユーザーの削除とユーザー権限の取り消し
  • ユーザーとその権限の取り消し:
  •  syntax:
        drop user username;
        example:
        drop user shine@'%';
        drop user shine@'localhost';
  • ユーザー権限の取り消し:
  •     syntax:
        revoke privilege on databasename.tablename from 'username'@'host';
        example:
        revoke select on *.* from 'shine'@'%';
        revoke update on demo.user from 'shine'@'%';
        revoke all on *.* from 'shine'@'%';
  • 表示権限ユーザー権限:
  •   syntax:
        show grants for 'username'@'hostname/IP';
        example:
        show grants for 'shine'@'192.168.2.101';
  • 削除ユーザ:
  •     syntax:
        delete from user where user = "username" and host="hostname/IP";
        example:
        delete from user where user = "shine" and host='192.168.2.101';

  • 9.