リレーショナルデータベースサーバーには、OracleやマイクロソフトのSQL Server等高価なものが多い中、PostgreSQL と MySQL はフリーのサーバーとして重宝します。ただし、PostgreSQLはLinuxとSolaris用しかなく、Windowsで使えるものはMySQLに限られるようです。
C:\mysql\bin > mysql -u root ##←パスワードオプション(-p)を指定せず。
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)
C:\mysql\bin>mysql -u root -p ##←パスワードを指定
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9 to server version: 3.23.41-max-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
mysql>
C:\mysql\bin > mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.23.41-max-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql > use mysql ##←mysqlデータベースを使うことを宣言
Database changed
mysql > show tables; ##←テーブルの一覧を表示
+-----------------+
| Tables_in_mysql |
+-----------------+
| columns_priv |
| db |
| host |
| tables_priv |
| user | ##←このuserテーブルにユーザー情報が保管されている。
+-----------------+
5 rows in set (0.05 sec)
mysql > select * from user; ##←userテーブルからすべて表示
+-----------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv |
+-----------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+
| localhost | root | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y |
| % | | | N | N | N | N | N | N | N | N | N | N | N | N | N | N |
| localhost | | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y |
| % | root | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y |
+-----------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+
4 rows in set (0.06 sec)
この user テーブルの???_privは、およそ次のような意味です。データベースからを表示するだけなら、「select_priv」のみでOKです。
C:\mysql\bin > mysqlshow
+-----------+
| Databases |
+-----------+
| mysql |
| test |
+-----------+
クライアントプログラムを実行します。色々ありますが、\bin\mysql.exe を使います。
C:\mysql\bin>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9 to server version: 3.23.41-max-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql >
mysqlシェル上のヘルプは次のようにすると表示されます。
mysq l> help
MySQL commands:
Note that all text commands must be first on line and end with ';'
help (\h) Display this help.
? (\?) Synonym for `help'.
clear (\c) Clear command.
connect (\r) Reconnect to the server. Optional arguments are db and host.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
notee (\t) Don't write into outfile.
print (\p) Print current command.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute a SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
Connection id: 12 (Can be used with mysqladmin kill)
C:\mysql\bin > mysqladmin -u root -p create jinji
Enter password: ********
C:\mysql\bin > mysqlshow
+-----------+
| Databases |
+-----------+
| jinji | ←jinjiデータベースが増えた!!
| mysql |
| test |
+-----------+
逆に、データベースを削除するときは、 「mysqladmin -u root -p drop test「?とすればOKです。(パスワードなければ-pは不要)
新しく作った「jinji」データベースにログインします。
C:\mysql\bin > mysql -u root -p jinji
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19 to server version: 3.23.41-max-debug
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql >