MySQL数据库的介绍
    什么是数据库
    数据库(Database)就是按照数据结构来组织,存储和管理数据的仓库
    专业的数据库是专门对数据进行创建,访问,管理,搜索等操作的软件,比起我们自己用文件读 写的方式对象数据进行管理更加的方便,快速,安全
    作用
    •对数据进行持久化的保存
    •方便数据的存储和查询,速度快,安全,方便
    •可以处理并发访问
    •更加安全的权限管理访问机制
    常见的数据库
    |数据库分两大类,一类是关系型数据库。另一类叫做非关系型数据库。
    •关系型数据库:MySQL, Oracle, PostgreSQL, SQLServer。。。。
    •非关系型数据库:Redis内存数据库,MongoDB文档数据库。。。
    认识mysq I数据库
    mysql中的基本概念
    •库Database可以类比为电脑中的文件夹,可以创建很多个不同的文件夹
    •表table库中表,类比为文件夹中的文件,存储着具体的数据
    •表引擎对数据的操作全部由表引擎完成,mysql中常用的表引擎为:InnoDB和Myisam
    1.MySQL数据库的介绍 - 图1

    16.00 KB,
    Navicc
    连接 新建查询 表
    f(x)
    函数 其它
    a i® I
    查询备份自动运行模
    用户
    表引擎1
    16.00 KB InnoDB
    16.00 KB InnoDB
    16.00 KB InnoDB
    16.00 KB InnoDB
    16.00 KB InnoDB mnn<|BjlnnoDB | 16.00 KB InnoDB
    16.00 KB InnoDB
    16.00 KB InnoDB
    16.00 KB InnoDB
    16.00 KB InnoDB
    16.00 KB InnoDB
    16.00 KB InnoDB
    736256.00 KB InnoDB
    16.00 KB InnoDB
    Database <
    Table
    A旣88
    A为函数
    ►①事件
    A奪査询
    A田备份
    喜 information schema
    ► S mysql
    Sperformance_schema
    数据长度
    16.00 KB InnoDB
    ▼ n Mysql
    § bookshop
    A T| S chuange
    对象
    > ® Course customers 薜 del_users ® mst_a 3 mst_b H mst_class —“^^”msTstu
    田 mst_weather 封 mst.zhubo orderitems 薜 orders productnotel ffl products ffi SC 却 Student Teacher
    3 users 申 vendors
    表中的概念
    •字段Field类似于Exce I中的表头,在mysq I中称为字段。是记录当前列的名字
    •列col,-列数据的类型是相同的
    •行row,—个完整的数据记录称为一行
    1.MySQL数据库的介绍 - 图2

    其它
    张三
    赵六
    熊二
    备份
    表头Header 字段Field
    列col
    行row
    Navicat Pren
    15 圖
    自动运行模型
    ▼ n Mysql 晝 bookshop
    ▼受 chuange
    ~~ ~~▼旺
    即 Course
    customers 薜 del_users mst_a
    H mst b ffi mst_class
    H mst.stu 日m心奖 ~~薜 mst_zhubo M orderitems 薜 orders 薜 productnotes products fflsc 国 Student y ffl Teacher
    users vendors
    对象 ffl users@chuange (Mysql)
    phone
    email
    20 男 13701133013 zs@qq.com [
    o観
    连接 新建查询

    查询
    ls@qq.com
    ww@qq.com
    zl@qq.com
    tq@qq.com
    xd@qq.com
    xe@qq.com
    dd@qq.com
    ss@qq.com
    3王五
    6熊大
    8豆豆
    13701133014
    13701233015
    13701333016
    **
    10 ****0143W A~~**
    13701533018
    13701633019
    13701733010
    13701833011
    MySQL的基本操作

    1. 1.在终端链接mysql数据库<br />Enter password:如果有密码则输入密码回车,没有密码则直接回车<br />Welcome to the MySQL monitor. Commands end with ; or \g.<br />Your MySQL connection id is 12<br />Server version: 5.7.28 Homebrew<br />chuangede-MacBook-Pro:~ yc$<br />mysql -u root -p<br />Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.<br />Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.<br />Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.<br />A 2.查看所有库<br />mysql> I show databases;<br />I Database<br />information_schema bookshop chuange<br />mysql performance_schema sys

    6 rows 6n set (0.01 sec) mysql> I use chuange;

    3.打开/进入/选择库
    Database changed
    mysql>
    金 yc bash — 92x33
    mysql> use chuange;
    Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
    Database chanaed mysql>|show tables;
    查看当前库中所有的表
    I Tables_in_chuange |
    customers orderitems orders productnotes products users vendors

    +-
    1
    + id | name -+-
    1
    +
    age | sex
    -+
    | phone
    -+ +
    | email |
    4— -L 4- -1. a
    1 1 1张三 1 20 |男 | 13701133013 | zs@qq.com |
    1 2 |李四 1 22 |男 | 13701133014 | ls@qq.com |
    1 3 |王五 1 21 |女 | 13701233015 | ww@qq.com |
    1 4 |赵六 1 20 |男 | 13701333016 | zl@qq.com |
    1 5 |田七 1 27 |女 | 13701433017 | tq@qq.com |
    1 6 |熊大 1 24 |男 | 13701533018 | xd@qq.com |
    1 7 |熊二 1 23 |女 | 13701633019 | xe@qq.com |
    1 8 |豆豆 1 22 |女 | 13701733010 | dd@qq.com |
    1
    4—
    9 |思思
    -1.
    1
    4-
    28 |男
    4-
    | 13701833011
    -1.
    | ss@qq.com |
    9 rows in set (0 .00 sec)

    7 rows in set (0.01 sec) mysql> select * from users;

    select 关键字代表查询
    * 代表查询的列(字段)有哪些*表示所有列
    from 关键字表示从哪个表中查询
    users 表示要查询的表
    mysql中默认的语句结尾符

    mysql> desc users;

    查看表结构

    Field
    I Type
    I Null I Key | Default | Extra

    | int(10) unsigned NO PRI NULL |
    | varchar(20) YES NULL |
    I int(ll) YES NULL |
    | varchar(l) YES NULL |
    | varchar(ll) YES NULL |
    | varchar(100)
    X J
    YES
    J
    NULL 1
    _ x.

    auto increment

    show 关键字表示查看/显示
    create 关键字表示创建
    table 关键字表示表
    users 查看的表
    \G 格式化结果

    9
    表示sql语句的结尾

    id name age sex phone email
    6 rows in set (0.00 sec) mysql> show create table users\G;
    Table: users
    Create Table: CREATE TABLE ‘users’ (
    ‘id’ int(10) unsigned NOT NULL AUTO_INCREMENT,
    ‘name’ varchar(20) DEFAULT NULL,
    ‘age’ int(ll) DEFAULT NULL,
    ‘sex’ varchar(l) DEFAULT NULL,
    ‘phone’ varchar(ll) DEFAULT NULL,
    ‘email’ varchar(100) DEFAULT NULL, PRIMARY KEY (‘id’)
    )ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4
    1 row in set (0.00 sec)