博客
关于我
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/

    你可能感兴趣的文章
    Nmap扫描教程之Nmap基础知识
    查看>>
    Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
    查看>>
    NMAP网络扫描工具的安装与使用
    查看>>
    NMF(非负矩阵分解)
    查看>>
    nmon_x86_64_centos7工具如何使用
    查看>>
    NN&DL4.1 Deep L-layer neural network简介
    查看>>
    NN&DL4.3 Getting your matrix dimensions right
    查看>>
    NN&DL4.8 What does this have to do with the brain?
    查看>>
    nnU-Net 终极指南
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    NO 157 去掉禅道访问地址中的zentao
    查看>>
    no available service ‘default‘ found, please make sure registry config corre seata
    查看>>
    no connection could be made because the target machine actively refused it.问题解决
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
    查看>>
    No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
    查看>>
    No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
    查看>>
    No module named 'crispy_forms'等使用pycharm开发
    查看>>
    No module named cv2
    查看>>