MYSQLデータベース操作

3668 ワード

SQL分類
DDL (      )
         - Data Definition Language
            ,    、  、   
DML  (      )
         - Data Manipulation Language
          ,       
    update, insert, delete ---    
DCL (      )
         – Data Control Language
                  
   grant,revoke,if…else,while,begin transaction
DQL (      )
         – Data Query Language
  select

データベース操作
  • 1.データベース作成
  •    :
       create database      ;
         : create database day06;
    
       :
       create database       character set    ;
         : create database day06_1 character set utf8;
    
       :
       create database       character set     collate     ;
         : create database day06_2 character set utf8 collate utf8_bin;
    

    次のように正常に印刷されました.
    Query OK, 1 row affected, 1 warning (0.05 sec)
  • 2.データベースの表示
  •        
      show databases;    
    
              
      show create database      ;
        :show create database day06;
        :show create database day06_1;
    
    

    クエリは次のように印刷されました.
    mysql> show databases; +--------------------+ | Database | +--------------------+ | day06 | | day06_1 | | day06_2 | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 7 rows in set (0.00 sec)
    +----------+----------------------------------------------------------------------------------------------+ | Database | Create Database | +----------+----------------------------------------------------------------------------------------------+ | day06 | CREATE DATABASE day06 /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */| +----------+----------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
  • 3.データベース操作の変更
  •         
      alter database        character set    ;
        :  alter database day06_1 character set gbk;
    
    

    変更前に次のように印刷します.
    mysql> mysql> show create database day06_1; +----------+------------------------------------------------------------------+ | Database | Create Database | +----------+------------------------------------------------------------------+ | day06_1 | CREATE DATABASE day06_1 /*!40100 DEFAULT CHARACTER SET utf8 */| +----------+------------------------------------------------------------------+ 1 row in set (0.00 sec)
    変更
    mysql> alter database day06_1 character set gbk; Query OK, 1 row affected (0.06 sec)
    変更後、次のように印刷されます.
    mysql> show create database day06_1; +----------+-----------------------------------------------------------------+ | Database | Create Database | +----------+-----------------------------------------------------------------+ | day06_1 | CREATE DATABASE day06_1 /*!40100 DEFAULT CHARACTER SET gbk */| +----------+-----------------------------------------------------------------+ 1 row in set (0.00 sec)
  • 4.データベースの削除
  • drop database      ;
      :  drop database day06_1;
    

    次のように印刷します.
    データベースの削除
    mysql> drop database day06_1; Query OK, 0 rows affected (0.04 sec)
    クエリーデータベース、day 06_1は削除されたことを示します
    mysql> show databases; +--------------------+ | Database | +--------------------+ | day06 | | day06_2 | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 6 rows in set (0.00 sec)
  • 5.その他のデータベース操作
  • use      ;
      : use day06;
    
                  
      :select database();
    

    次のように印刷します.
    mysql> use day06; Database changed
    mysql> select database(); +------------+ | database() | +------------+ | day06 | +------------+ 1 row in set (0.01 sec)