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

    你可能感兴趣的文章
    SSM(Spring+SpringMvc+Mybatis)整合开发笔记
    查看>>
    ViewHolder的改进写法
    查看>>
    Orderer节点启动报错解决方案:Not bootstrapping because of 3 existing channels
    查看>>
    org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement profile
    查看>>
    sql查询中 查询字段数据类型 int 与 String 出现问题
    查看>>
    org.apache.commons.beanutils.BasicDynaBean cannot be cast to ...
    查看>>
    org.apache.dubbo.common.serialize.SerializationException: com.alibaba.fastjson2.JSONException: not s
    查看>>
    sqlserver学习笔记(三)—— 为数据库添加新的用户
    查看>>
    org.apache.http.conn.HttpHostConnectException: Connection to refused
    查看>>
    org.apache.ibatis.binding.BindingException: Invalid bound statement错误一例
    查看>>
    org.apache.ibatis.exceptions.PersistenceException:
    查看>>
    org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
    查看>>
    org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
    查看>>
    org.apache.poi.hssf.util.Region
    查看>>
    org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
    查看>>
    org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
    查看>>
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processDebugManifest'
    查看>>
    org.hibernate.HibernateException: Unable to get the default Bean Validation factory
    查看>>
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
    查看>>
    org.springframework.amqp.AmqpConnectException:java.net.ConnectException:Connection timed out:connect
    查看>>