站点图标 IDC铺

关于MySQL架构及SQL语句

MySQL:单进程多线程
MySQL数据文件类型:
数据文件、索引文件
日志文件:重做日志、撤销日志、二进制日志、错误日志、查询日志、慢查询日志、中继日志

DDL & DML:
索引管理:按特定数据结构存储的数据
索引类型:
聚集索引(一般都是主键索引)、非聚集索引、数据是否与索引存储在一起
主键索引、辅助索引
稠密索引、稀疏索引:是否索引了每一个数据项
B+ TREE(B指的是Balance)平衡树索引、HASH索引、R TREE索引
简单索引、组合索引

MySQL索引的使用方式:左前缀索引(最左前缀索引)
覆盖索引:不需要查找元数据,只通过索引就可以找到想到的数据

管理索引的途径:
创建索引: 创建表时指定:CREATE INDEX
创建或删除索引:修改表的命令
删除索引:DROP INDEX

查看表上的索引:
SHOW {INDEX | INDEXES | KEYS}
    {FROM | IN} tbl_name
    [{FROM | IN} db_name]
    [WHERE expr]
SHOW INDEXES FROM user;

使用EXPLAIN查看语句分析结果:
EXPLAIN SELECT * FROM user WHERE User='root'\G;

视图:VIEW
    虚表
    创建方法:
    CREATE
        [OR REPLACE]
        [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
        [DEFINER = { user | CURRENT_USER }]
        [SQL SECURITY { DEFINER | INVOKER }]
        VIEW view_name [(column_list)]
        AS select_statement
        [WITH [CASCADED | LOCAL] CHECK OPTION]
创建一个test的视图:CREATE VIEW test AS SELECT User,Host FROM user;

视图中的数据事实上存储于"基表"中,因此,其修改操作也会针对基表实现,其修改操作受基表限制;

DML:
    INSERT, DELETE, UPDATE, SELECT
    INSERT:
        一次插入一行或多行数据
        Syntax:
        INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
            [INTO] tbl_name
            [PARTITION (partition_name,...)]
            [(col_name,...)]
            {VALUES | VALUE} ({expr | DEFAULT},...),(...),...
            [ ON DUPLICATE KEY UPDATE
              col_name=expr
                [, col_name=expr] ... ]

        Or:

        INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
            [INTO] tbl_name
            [PARTITION (partition_name,...)]
            SET col_name={expr | DEFAULT}, ...
            [ ON DUPLICATE KEY UPDATE
              col_name=expr
                [, col_name=expr] ... ]

        Or:

        INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE]
            [INTO] tbl_name
            [PARTITION (partition_name,...)]
            [(col_name,...)]
            SELECT ...
            [ ON DUPLICATE KEY UPDATE
              col_name=expr
                [, col_name=expr] ... ]

    DELETE:
        DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name
            [PARTITION (partition_name,...)]
            [WHERE where_condition]
            [ORDER BY ...]
            [LIMIT row_count]
        注意:一定要有限制条件,否则将清空表中的所有数据
            WHERE
            LIMIT

    UPDATE:
        UPDATE [LOW_PRIORITY] [IGNORE] table_reference
            SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
            [WHERE where_condition]
            [ORDER BY ...]
            [LIMIT row_count]
          注意:一定要有限制条件,否则将修改所有行的指定字段
            WHERE
            LIMIT
退出移动版