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

    你可能感兴趣的文章
    python读取mtcars数据集并实现以下操作_关于数据处理。。,Python交流,技术交流区,鱼C论坛 - Powered by Discuz!...
    查看>>
    Python 中多线程与多处理之间的区别
    查看>>
    Python 中如何使用 lambda 函数
    查看>>
    Python 中如何创建多行字符串?
    查看>>
    Python 中如何处理异常?
    查看>>
    Python 中如何实现列表的切片?
    查看>>
    Python 中如何实现字典的排序?
    查看>>
    Python 中常用的数据类型及相关操作详解
    查看>>
    python 中文乱码
    查看>>
    Python 中生成器与普通函数的区别
    查看>>
    Python 中的 *tuple 和 **dict 是什么意思?
    查看>>
    Python 中的 filter() 函数:筛选可迭代对象元素
    查看>>
    Python 中的 Pillow 不允许我打开图像(“超出限制“)
    查看>>
    Python 中的 threading 模块和 multiprocessing 模块有何区别?
    查看>>
    Python 中的 threading 模块和 multiprocessing 模块有何区别?
    查看>>
    Python 中的 Turtle 库详解
    查看>>
    Python 中的 __slots__ 属性有什么作用?
    查看>>
    Python 中的... 三点、箭头(->)、/ 分别的作用
    查看>>
    python读取json数据的id_python处理JSON数据
    查看>>
    Python 中的Duck Typing
    查看>>