データベースの作成
データベースの作成はCREATE DATABASE
コマンドを使う。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
mysql> create database ??????????_test; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | ??????????_main | | ??????????_test | | ??????????_wp1 | +--------------------+<code></code> 4 rows in set (0.10 sec) mysql> |
ただし、さくらレンタルサーバの場合はwebのコントロールパネルでデータベースを作成・削除する方法のみが示されていて、コンソールでのコマンド操作はエラーとなる。
1 2 |
mysql> create database taustation_temp; ERROR 1044 (42000): Access denied for user 'taustation'@'%' to database 'taustation_temp' |
データベースアクセスの権限設定
必要に応じて、ユーザーへのデータベースアクセスの権限を設定する。
GRANT ALL PRIVILEGES ON dbname.* TO dbuser@'localhost'
データベースの削除
データベースの削除にはDROP DATABASE
コマンドを使う。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
mysql> drop database ??????????_test; Query OK, 0 rows affected (0.01 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | ??????????_main | | ??????????_wp1 | +--------------------+ 3 rows in set (0.11 sec) mysql> |
存在しないデータベースを削除しようとするとエラーになるが、DROP DATABASE IF EXISTSコマンドを使うと、データベースが存在しない場合もエラーにならない。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | ??????????_main | | ??????????_test | | ??????????_wp1 | +--------------------+ 4 rows in set (0.10 sec) mysql> drop database if exists ??????????_test; Query OK, 0 rows affected (0.01 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | ??????????_main | | ??????????_wp1 | +--------------------+ 3 rows in set (0.11 sec) mysql> drop database if exists ??????????_test; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> drop database ??????????_test; ERROR 1044 (42000): Access denied for user 'taustation'@'%' to database 'taustation_foo' mysql> |