1. Create a database
  • grammar

CREATE DATABASE [IF NOT EXISTS]

  • Create specification described | | specification | | — – | — – | — – | | [DEFAULT] CHARACTER SET CHARACTER SET | specify the database CHARACTER SET | | [DEFAULT] COLLATE CHARACTER SET | | CHARACTER SET to proofread rules
  • Create database with default character set:
    create database study;
    Copy the code

    Specify database specify character set (UTF8) :

    create database study DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
    Copy the code

    SQL > select * from character set;

    show character set;
    Copy the code

    Create database does not exist:

    create database if not exists study;
    Copy the code

    Note: If you specify the character set at compile time, you do not need to specify the character set to create the corresponding database later

2. Display the database
  • Grammar SHOW DATABASES [LIKE ‘pattern’ | WHERE expr]

  • Description parameters | | | | — – | — – | — – | | | | regular like regular expression matching the specified library

  • Operation display all libraries:

    show databases;
    Copy the code

    View library name for all stU libraries:

    show databases like '%stu%';
    Copy the code
3. View the database creation statement
  • Syntax SHOW CREATE DATABASE [IF NOT EXISTS] Specifies the name of the DATABASE
  • operation
    show create database study\G
    Copy the code
4. View the connected database
  • Grammar to select the database ();
5. Connect to the database
  • Syntax USE< database name >
  • operation
    use study;   
    Copy the code
6. Delete the database
  • grammar

DROP DATABASE [IF EXISTS] Specifies the name of the DATABASE

  • operation
    drop database study;
    Copy the code