database

作者: 圼_2514 | 来源:发表于2019-01-18 13:42 被阅读0次

    1.查看所有database
    show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    | sys |
    +--------------------+
    2.创建database
    2.1 创建不存在的database
    mysql> create database testdb;
    Query OK, 1 row affected (0.01 sec)
    2.1 创建已存在的database
    mysql> create database testdb;
    ERROR 1007 (HY000): Can't create database 'testdb'; database exists
    2.3 如果存在不创建,不存在才创建
    2.3.1 已存在
    mysql> create database if not exists testdb;
    Query OK, 1 row affected, 1 warning (0.00 sec)
    2.3.2 不存在
    mysql> create database if not exists testdb;
    Query OK, 1 row affected (0.00 sec)

    3.删除database
    3.1 删除已存在的database
    mysql> drop database testdb;
    Query OK, 0 rows affected (0.00 sec)
    3.2 删除不存在的database
    mysql> drop database testdb;
    ERROR 1008 (HY000): Can't drop database 'testdb'; database doesn't exist
    3.3 存在才删除
    mysql> drop database if exists testdb;
    Query OK, 0 rows affected, 1 warning (0.00 sec)

    相关文章

      网友评论

          本文标题:database

          本文链接:https://www.haomeiwen.com/subject/hhkndqtx.html