茨の道も一歩から

インフラ構築からプログラミング(Python・JavaScript)までITに関するブログです。

107日目:データベース

データベースの講義6日目です。

【参考テキスト】

【講義内容】

  • 第5章 DBMSを操作する際の基本知識-操作する前に知っておくこと

【ワンポイント】

ビューの作成

CREATE VIEW CityJapan AS SELECT * FROM City WHERE CountryCode = 'JPN';

ビューの削除

DROP VIEW IF EXISTS CityJapan;
  • IF EXISTSあり:削除対象のビューが無い場合warningとなる。
Query OK, 0 rows affected, 1 warning (0.00 sec)
  • IF EXISTSなし:削除対象のビューが無い場合Errorとなる。
ERROR 1051 (42S02): Unknown table 'world.cityjapan'

【今日の積み上げ】

‐ データベースの基礎

106日目:データベース

データベースの講義5日目です。

【参考テキスト】

【講義内容】

  • 第5章 DBMSを操作する際の基本知識-操作する前に知っておくこと

【ワンポイント】

MySQL HELP

mysql> help

For information about MySQL products and services, visit:
   http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
   http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
   https://shop.mysql.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
notee     (\t) Don't write into outfile.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
resetconnection(\x) Clean session context.

For server side help, type 'help contents'

【今日の積み上げ】

‐ データベースの基礎

105日目:データベース

データベースの講義4日目です。

【参考テキスト】

【講義内容】

  • 第5章 DBMSを操作する際の基本知識-操作する前に知っておくこと

【ワンポイント】

コネクション数の確認

SHOW STATUS LIKE 'Threads_connected';

出力結果

+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_connected | 1     |
+-------------------+-------+
1 row in set (0.00 sec)

SHOW構文

文字コードの確認

SHOW VARIABLES LIKE '%chara%';

出力結果

+--------------------------+-------------------------------+
| Variable_name            | Value                         |
+--------------------------+-------------------------------+
| character_set_client     | cp932                         |
| character_set_connection | cp932                         |
| character_set_database   | utf8mb4                       |
| character_set_filesystem | binary                        |
| character_set_results    | cp932                         |
| character_set_server     | utf8mb4                       |
| character_set_system     | utf8                          |
| character_sets_dir       | C:\Dev\mysql8\share\charsets\ |
+--------------------------+-------------------------------+
8 rows in set, 1 warning (0.01 sec)

テーブルステータスの確認

SHOW TABLE STATUS FROM meat_shop WHERE Name='meats' \G

出力結果

*************************** 1. row ***************************
           Name: meats
         Engine: InnoDB
        Version: 10
     Row_format: Dynamic
           Rows: 11
 Avg_row_length: 1489
    Data_length: 16384
Max_data_length: 0
   Index_length: 0
      Data_free: 0
 Auto_increment: 12
    Create_time: 2020-10-23 12:00:26
    Update_time: 2020-10-26 10:57:48
     Check_time: NULL
      Collation: utf8_general_ci
       Checksum: NULL
 Create_options:
        Comment:
1 row in set (0.00 sec)

【今日の積み上げ】

‐ データベースの基礎