zoukankan      html  css  js  c++  java
  • MySQL相关信息之数据库操作(三)

    1、创建数据库

    CREATE  {DATABASE  |  SCHEMA}  [IF NOT EXISTS]  DB_NAME

    [DEFAULT]  CHARACTER SET [=] charset_name

    {}为必选项,[]为可选项

    root@localhost test>CREATE DATABASE t1;
    Query OK, 1 row affected (0.03 sec)

    2、查看存在的所有的数据库

    root@localhost test>SHOW DATABASES;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    | t1 |
    | test |
    +--------------------+
    5 rows in set (0.00 sec)

    root@localhost test>

    3、查看数据库的编码方式

    root@localhost test>SHOW CREATE DATABASE t1;
    +----------+-------------------------------------------------------------+
    | Database | Create Database |
    +----------+-------------------------------------------------------------+
    | t1 | CREATE DATABASE `t1` /*!40100 DEFAULT CHARACTER SET utf8 */ |
    +----------+-------------------------------------------------------------+
    1 row in set (0.00 sec)

    4、数据库编码格式设定为gbk

    root@localhost test>CREATE DATABASE IF NOT EXISTS t2 CHARACTER SET gbk;
    Query OK, 1 row affected (0.00 sec)

    root@localhost test>SHOW CREATE DATABASE t2;
    +----------+------------------------------------------------------------
    | Database | Create Database
    +----------+------------------------------------------------------------
    | t2 | CREATE DATABASE `t2` /*!40100 DEFAULT CHARACTER SET gbk */
    +----------+------------------------------------------------------------
    1 row in set (0.00 sec)

    5、修改数据库

    ALTER {DATABASE  |  SCHEMA} [db_name]

    [default] CHARACTER SET [=] charset_name

    把数据库的编码格式由gbk修改为utf8

    root@localhost test>ALTER DATABASE t2 CHARACTER SET utf8;
    Query OK, 1 row affected (0.00 sec)

    root@localhost test>SHOW CREATE DATABASE t2;
    +----------+-------------------------------------------------------------+
    | Database | Create Database |
    +----------+-------------------------------------------------------------+
    | t2 | CREATE DATABASE `t2` /*!40100 DEFAULT CHARACTER SET utf8 */ |
    +----------+-------------------------------------------------------------+
    1 row in set (0.00 sec)

    6、删除数据库

    DROP {DATABASE  |  SCHEMA} [IF EXISTS] db_name

    root@localhost test>DROP DATABASE t1;
    Query OK, 0 rows affected (0.05 sec)

    root@localhost test>SHOW DATABASES;  #查看警告
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    | t2 |
    | test |
    +--------------------+
    5 rows in set (0.00 sec)

    root@localhost test>DROP DATABASE t1;
    ERROR 1008 (HY000): Can't drop database 't1'; database doesn't exist
    root@localhost test>DROP DATABASE IF EXISTS t1;
    Query OK, 0 rows affected, 1 warning (0.00 sec)

    root@localhost test>SHOW WARNINGS;
    +-------+------+--------------------------------------------------+
    | Level | Code | Message |
    +-------+------+--------------------------------------------------+
    | Note | 1008 | Can't drop database 't1'; database doesn't exist |
    +-------+------+--------------------------------------------------+
    1 row in set (0.00 sec)

  • 相关阅读:
    1级搭建类106-Oracle 19c 单实例 FS(华为云)公开
    table表格超出部分显示省略号
    hibernate自动创建表报表不存在
    TCP/IP协议三次握手与四次挥手
    struts2运行流程
    Errors occurred during the build. Errors running builder 'Validation' on pro
    ads查询结果中文显示方框问题
    plsql登录报错身份证明检索失败
    隐藏域传值到后台controller
    获取select被选中的option的值
  • 原文地址:https://www.cnblogs.com/toudoubao/p/6554965.html
Copyright © 2011-2022 走看看