博客
关于我
MySQL-01——数据库、表、数据相关操作
阅读量:208 次
发布时间:2019-02-28

本文共 984 字,大约阅读时间需要 3 分钟。

MySQL-01——数据库、表、数据相关操作

数据库相关

数据库是MySQL中最基本的管理单元,以下是一些常用的数据库操作命令:

  • 列出所有存在的数据库:
  • show databases;
    1. 创建一个新的数据库(这里以db1为例):
    2. create database db1 character set utf8/gbk;
      1. 查看特定数据库的创建语句:
      2. show create database db1;
        1. 删除指定数据库:
        2. drop database db1;
          1. 切换到指定数据库进行操作:
          2. use db1;

            表相关

            表是数据库中用来存储数据的主要载体,以下是一些与表操作相关的命令:

          3. 创建一个新表(以下示例中t1为表名称):
          4. create table t1(name varchar(10) , age int )engine=myisam/innodb charset=utf8/gbk;
            1. 查看所有存在的表:
            2. show tables;
              1. 查看某个表的创建语句:
              2. show create table t1;
                1. 查看表的字段信息:
                2. desc t1;
                  1. 删除指定表:
                  2. drop table t1;
                    1. 重命名表:
                    2. rename table t1 to t2;
                      1. 修改表的存储引擎和字符集:
                      2. alter table t1 engine=mysiam/ innodb charset=utf8/gbk;
                        1. 在表中添加新字段:
                        2. alter table t1 add字段名 类型 first/after xxx;
                          1. 删除表中的字段:
                          2. alter table t1 drop字段名;
                            1. 修改字段名称和类型:
                            2. alter table t1 change 原名 新名 新类型;
                              1. 修改字段的位置:
                              2. alter table t1 modify 字段名 新类型 first/after xxx;

                                数据相关

                                数据是表中存储的具体信息,以下是一些与数据操作相关的命令:

                              3. 插入新数据:
                              4. insert into t1 (name, age) values('小明',28),('小花',38);
                                1. 查询数据:
                                2. select name,age from t1 where id<10;
                                  1. 更新数据:
                                  2. update t1 set age=50 where id=5;
                                    1. 删除数据:
                                    2. delete from t1 where age<30;

    转载地址:http://jhzs.baihongyu.com/

    你可能感兴趣的文章
    POJ 2484 A Funny Game(神题!)
    查看>>
    POJ 2486 树形dp
    查看>>
    POJ 2488:A Knight&#39;s Journey
    查看>>
    SpringBoot为什么易学难精?
    查看>>
    poj 2545 Hamming Problem
    查看>>
    poj 2723
    查看>>
    poj 2763 Housewife Wind
    查看>>
    Qt笔记——模型/视图MVD 文件目录浏览器软件
    查看>>
    POJ 2892 Tunnel Warfare(树状数组+二分)
    查看>>
    poj 2965 The Pilots Brothers' refrigerator-1
    查看>>
    poj 3026( Borg Maze BFS + Prim)
    查看>>
    POJ 3041 - 最大二分匹配
    查看>>
    POJ 3041 Asteroids(二分匹配模板题)
    查看>>
    Qt笔记——标准文件对话框QFileDialog
    查看>>
    poj 3083 Children of the Candy Corn
    查看>>
    POJ 3083 Children of the Candy Corn 解题报告
    查看>>
    POJ 3253 Fence Repair C++ STL multiset 可解 (同51nod 1117 聪明的木匠)
    查看>>
    Qt笔记——控件总结
    查看>>
    poj 3262 Protecting the Flowers 贪心
    查看>>
    poj 3264(简单线段树)
    查看>>