博客
关于我
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 如果文件夹不存在就创建文件夹
    查看>>
    Python 如果有很多或以收缩形式
    查看>>
    Python 子进程 Popen 与 Pyinstaller
    查看>>
    Python 子进程 Popen.communicate() 等价于 Popen.stdout.read()?
    查看>>
    Python 子进程 Popen:为什么会出现“ls *.txt“?不行?
    查看>>
    Python 子进程参数
    查看>>
    python 字典 key 和value 互换
    查看>>
    Python 字典 vs If 语句速度
    查看>>
    python 字典sorted自定义排序,按照key or value排序
    查看>>
    python 字典和列表区别_元组列表和字典的主要区别是什么?
    查看>>
    python 字符串中特定字符替换,截取
    查看>>
    Python 字符串总结
    查看>>
    python 字符串显示中文_Python字符串开头的b"、u"、r"与中文乱码
    查看>>
    Python 字符串的几种拼装方式
    查看>>
    python 存入数据库bigint_python基础_MySQL的bigint类型
    查看>>
    python 学习 面向对象编程
    查看>>
    Python 学习小结
    查看>>
    Python 学习日记第三篇 -- 字典
    查看>>
    Python 学习笔记(一)Data type
    查看>>
    python 安装 easy_install 和 pip 流程
    查看>>