広告
広告
https://www.7key.jp/software/mysql.html#a_01default-character-set=sjishttps://www.7key.jp/software/mysql.html#a_02c:\>mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 448 to server version: 5.0.0-alpha-nt Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> grant all on *.* to root@localhost identified by 'password'; Query OK, 0 rows affected (0.08 sec)
https://www.7key.jp/software/mysql.html#a_03c:\>mysql -u root -p Enter password: password Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 448 to server version: 5.0.0-alpha-nt Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>
https://www.7key.jp/software/mysql.html#a_04mysql> show databases; +-----------+ | Database | +-----------+ | mysql | | test | +-----------+ 3 rows in set (0.00 sec) mysql>
https://www.7key.jp/software/mysql.html#a_05mysql> use mysql; Database changed mysql>
https://www.7key.jp/software/mysql.html#a_06mysql> create database dummy; Query OK, 1 row affected (0.00 sec) mysql> drop database dummy; Query OK, 0 rows affected (0.00 sec) mysql>
https://www.7key.jp/software/mysql.html#a_07前もって作成するデータベースを「use」コマンドにてアクティブにしておく。
create table テーブル名 ( フィールド定義, ... )
フィールド名 フィールド型 [not null | null] [default 初期値] [unique] [auto_increment] [primary key]
| フィールド名 | フィールド名を指定する。 | 
|---|---|
| フィールド型 | フィールドのデータ型を指定する。 
 
 | 
| 空文字許可 | 
 | 
| 初期値 | フィールドの初期値を設定する(default 0/default 'default') | 
| インデックス | 
 | 
| 自動裁番 | レコードが追加される度に、+1された値をフィールドに追加する。 auto_incrementはprimary keyと一緒に指定しなくてはならない。 | 
| 主キー | フィールドをテーブルの主キーにする。 primary keyを指定すると、そのフィールドにはnot nullが付加され、更にインデックスが自動的に作成される。 主キーもインデックスのように、複数フィールドで指定することができる。 | 
https://www.7key.jp/software/mysql.html#a_08mysql> drop table dummy_table; Query OK, 0 rows affected (0.03 sec) mysql>
https://www.7key.jp/software/mysql.html#a_09mysql> show tables; +-----------------+ | Tables_in_mysql | +-----------------+ | columns_priv | | db | | func | | help_category | | help_keyword | | help_relation | | help_topic | | host | | proc | | tables_priv | | user | +-----------------+ 11 rows in set (0.02 sec) mysql>
https://www.7key.jp/software/mysql.html#a_010mysql> desc db;
+-----------------------+---------------+------+-----+---------+-------+
| Field                 | Type          | Null | Key | Default | Extra |
+-----------------------+---------------+------+-----+---------+-------+
| Host                  | char(60)      |      | PRI |         |       |
| Db                    | char(64)      |      | PRI |         |       |
| User                  | char(16)      |      | PRI |         |       |
| Select_priv           | enum('N','Y') |      |     | N       |       |
| Insert_priv           | enum('N','Y') |      |     | N       |       |
| Update_priv           | enum('N','Y') |      |     | N       |       |
| Delete_priv           | enum('N','Y') |      |     | N       |       |
| Create_priv           | enum('N','Y') |      |     | N       |       |
| Drop_priv             | enum('N','Y') |      |     | N       |       |
| Grant_priv            | enum('N','Y') |      |     | N       |       |
| References_priv       | enum('N','Y') |      |     | N       |       |
| Index_priv            | enum('N','Y') |      |     | N       |       |
| Alter_priv            | enum('N','Y') |      |     | N       |       |
| Create_tmp_table_priv | enum('N','Y') |      |     | N       |       |
| Lock_tables_priv      | enum('N','Y') |      |     | N       |       |
+-----------------------+---------------+------+-----+---------+-------+
15 rows in set (0.06 sec)
mysql>
https://www.7key.jp/software/mysql.html#a_011create tableで作成したテーブルは、alter tableによって各種定義を以下のように変更する事ができる。
https://www.7key.jp/software/mysql.html#a_012mysql> source c:\dummy.sql mysql>
https://www.7key.jp/software/mysql.html#a_013grant 権限[(フィールド名[, フィールド名 ...])][, 権限[(フィールド名[, フィールド名 ...]) ... ] on データベース名.テーブル名 to ユーザ名[@ホスト名] [identified by 'パスワード'] [with grant option]
| 権限・フィールド名 | 
 | 
|---|---|
| データベース.テーブル名 | on [データベース名].[テーブル名]権限を付与するデータベースと、テーブル名を指定する。 (上記権限・フィールド名と連携) | 
| ユーザ・ホスト名 | to [ユーザ名]@[ホスト名]権限を付与するユーザを指定する。 MySQLがインストールされている端末の場合、ホスト名はlocalhostとなり、 特定の端末の場合は、その端末のPC名(又はIPアドレス)を記述する。 localhost以外の全ての端末からの場合は書かないか、'%'とする。 | 
| パスワード | identified by 'パスワード'パスワードを設定する。 ユーザの新規作成の場合、記述しないとパスワードの無いユーザになる。 既にパスワードが設定されており、ユーザの権限を追加する場合は、省略すると既存のパスワードが使われる。 | 
| grant | with grant optionユーザ管理(grant)の権限を付与する。 | 
mysql> grant all on dummy.* to guest@localhost identified by 'guest'; Query OK, 0 rows affected (0.03 sec) mysql>
https://www.7key.jp/software/mysql.html#a_014mysql> revoke alter on dummy.* from guest@localhost; Query OK, 0 rows affected (0.01 sec) mysql>
https://www.7key.jp/software/mysql.html#a_015mysql> show grants for root@localhost; 1 row in set (0.06 sec) mysql>
https://www.7key.jp/software/mysql.html#a_016ユーザを削除する場合、システムの管理に使用しているデータベース、「mysql」から直接削除する。 mysqlでユーザ管理に使用されているテーブルは、「use」「db」「tables_priv」「columns_priv」である。 これらのテーブルに「user」「host」というフィールドがそれぞれにあるので、この中から指定の「ユーザ名@ホスト名」を削除することになる。
mysql> delete from user where user='guest' and host='localhost'; Query OK, 1 row affected (0.03 sec) mysql> delete from db where user='guest' and host='localhost'; Query OK, 1 row affected (0.03 sec) mysql> delete from tables_priv where user='guest' and host='localhost'; Query OK, 0 rows affected (0.03 sec) mysql> delete from columns_priv where user='guest' and host='localhost'; Query OK, 0 rows affected (0.03 sec) mysql> flush privileges; Query OK, 0 rows affected (0.03 sec) mysql>
広告