本书系统介绍MySQL 5.7数据库管理系统的基础知识与开发工具。全书共分17章,内容包括数据库概述、安装和配置MySQL、操作MySQL数据库、MySQL存储引擎、数据类型、操作MySQL数据表、约束、函数、基本查询语句、进阶查询语句、视图、自定义函数、存储过程、触发器、索引、用户与权限、数据库恢复备份,最后介绍基于PHP语言和MySQL开发的企业项目开发案例。本书从初学者的角度,以丰富的实例、通俗易懂的语言、简单的图示,详细介绍MySQL使用和开发中重点用到的多种技术,可以让读者快速掌握MySQL数据库的使用方法。
封面图
目录
- 前 言
- 第1章 数据库概述 ·····································1
- 1.1 数据库基本概念 ·······························1
- 1.1.1 数据存储方式 ·······························1
- 1.1.2 什么是数据库 ············································2
- 1.1.3 数据库的存储结构 ····································2
- 1.1.4 数据库在开发中的作用 ···········································4
- 1.2 数据库技术 ··············································4
- 1.2.1 数据库系统 ·······························4
- 1.2.2 了解SQL语言 ·······································6
- 1.2.3 数据库访问技术 ···············································6
- 1.3 认识MySQL ···············································7
- 1.3.1 MySQL的优势 ······································7
- 1.3.2 MySQL的版本 ······································8
- 1.3.3 如何获取MySQL ···········································8
- 1.4 数据库的学习方法 ···········································10
- 1.5 小结 ·········································11
- 1.6 练习题 ·····································11
- 第2章 安装和配置MySQL ·········································12
- 2.1 MySQL 5.7的新特性 ·······································12
- 2.2 在不同平台上安装MySQL ·····································13
- 2.2.1 安装条件 ··············································13
- 2.2.2 在Windows系统上安装MySQL ········································13
- 2.2.3 在Linux系统上安装MySQL ································17
- 2.2.4 打开MySQL数据库 ··············································20
- 2.3 验证MySQL是否安装成功 ············································21
- 2.3.1 获取服务器状态 ············································22
- 2.3.2 执行简单的SQL 命令 ············································22
- 2.4 启动服务和登录MySQL 数据库 ·······································22
- 2.4.1 启动MySQL 服务 ··············································22
- 2.4.2 登录MySQL 数据库 ··············································23
- 2.4.3 配置Path 变量 ·····································25
- 2.5 配置MySQL 数据库 ········································26
- 2.5.1 使用配置向导 ······································26
- 2.5.2 手工更改配置 ······································30
- 2.6 使用MySQL Workbench 图形管理工具·····································30
- 2.7 使用免安装的MySQL ·····································31
- 2.8 小结 ·········································33
- 2.9 练习题 ·····································33
- 第3 章 操作MySQL 数据库 ········································ 34
- 3.1 创建数据库 ································34
- 3.1.1 基本语法 ··············································34
- 3.1.2 创建并查看数据库 ·······································35
- 3.1.3 创建指定字符集的数据库 ·····································36
- 3.2 修改数据库 ··········································37
- 3.2.1 基本语法 ··············································37
- 3.2.2 修改数据库的字符集 ·············································38
- 3.3 删除数据库 ·············································38
- 3.3.1 基本语法 ··············································38
- 3.3.2 删除数据库 ··········································39
- 3.4 选择数据库 ···········································40
- 3.5 使用图形界面管理数据库 ·····································40
- 3.6 综合案例 ·······························43
- 3.6.1 案例目的 ··············································43
- 3.6.2 案例演示过程 ······································44
- 3.7 小结 ·········································46
- 3.8 练习题 ·····································46
- 第4 章 MySQL 存储引擎与数据类型 ········································· 47
- 4.1 存储引擎 ·······························47
- 4.1.1 什么是存储引擎 ·········································47
- 4.1.2 MySQL 5.7 支持的存储引擎 ·································48
- 4.1.3 如何选择存储引擎 ··············································48
- 4.1.4 操作默认存储引擎 ·············································49
- 4.2 数据类型 ·······························49
- 4.2.1 整数类型 ··············································50
- 4.2.2 浮点数类型和定点数类型 ·····································51
- 4.2.3 日期与时间类型 ········································52
- 4.2.4 字符串和二进制类型 ··········································55
- 4.3 综合案例 ·······························59
- 4.3.1 案例目的 ··············································59
- 4.3.2 案例演示过程 ······································59
- 4.4 小结 ·········································60
- 4.5 练习题 ·····································60
- 第5 章 操 作 表 ········································ 62
- 5.1 表的基本概念 ··································62
- 5.2 创建表 ·····································62
- 5.2.1 基本语法 ··············································62
- 5.2.2 在指定的数据库中创建表 ·····································63
- 5.2.3 查看表结构 ··········································64
- 5.3 修改表 ·····································65
- 5.3.1 基本语法 ··············································66
- 5.3.2 添加字段 ··············································66
- 5.3.3 修改字段数据类型 ································67
- 5.3.4 删除字段 ··············································68
- 5.3.5 修改字段名称 ······································69
- 5.3.6 修改表名 ··············································69
- 5.4 删除表 ·····································70
- 5.4.1 基本语法 ··············································70
- 5.4.2 删除表 ·································70
- 5.5 使用图形界面操作数据表 ·································71
- 5.6 综合案例 ·······························75
- 5.6.1 案例目的 ··············································75
- 5.6.2 案例演示过程 ······································75
- 5.7 小结 ········································79
- 5.8 练习题 ·····································79
- 第6 章 约 束 ··········································· 80
- 6.1 约束的作用 ······································80
- 6.2 主键约束 ·······························80
- 6.2.1 选取设置主键约束的字段 ·····································80
- 6.2.2 在创建表时设置主键约束 ·····································81
- 6.2.3 在创建表时设置复合主键 ·····································82
- 6.2.4 在修改表时添加主键约束 ·····································83
- 6.2.5 使用图形界面操作主键约束 ·································83
- 6.3 外键约束 ·······························84
- 6.3.1 选取设置外键约束的字段 ·····································84
- 6.3.2 在创建表时设置外键约束 ·····································85
- 6.3.3 在修改表时添加外键约束 ·····································86
- 6.3.4 删除外键约束 ······································87
- 6.3.5 使用图形界面操作外键约束 ·································88
- 6.4 唯一约束 ·······························89
- 6.4.1 选取设置唯一约束的字段 ·····································89
- 6.4.2 在创建表时设置唯一约束 ·····································89
- 6.4.3 在修改表时添加唯一约束 ·····································90
- 6.4.4 删除唯一约束 ······································90
- 6.4.5 使用图形界面操作唯一约束 ·································91
- 6.5 检查约束 ·······························91
- 6.5.1 选取设置检查约束的字段 ·····································91
- 6.5.2 在创建表时设置检查约束 ·····································92
- 6.5.3 在修改表时添加检查约束 ·····································92
- 6.5.4 删除检查约束 ······································93
- 6.5.5 使用图形界面操作检查约束 ·································93
- 6.6 默认值约束 ······································93
- 6.6.1 选取设置默认值约束的字段 ·································93
- 6.6.2 在创建表时设置默认值约束 ·································93
- 6.6.3 在修改表时添加默认值约束 ·································94
- 6.6.4 删除默认值约束 ····································94
- 6.6.5 使用图形界面操作默认值约束 ········································95
- 6.7 非空约束 ·······························95
- 6.7.1 选取设置非空约束的字段 ·····································95
- 6.7.2 在创建表时设置非空约束 ·····································95
- 6.7.3 在修改表时添加非空约束 ·····································96
- 6.7.4 删除非空约束 ······································97
- 6.7.5 使用图形界面操作非空约束 ·································97
- 6.8 查看表中的约束 ···············································98
- 6.9 综合案例 ·······························98
- 6.9.1 案例目的 ··············································98
- 6.9.2 案例演示过程 ······································99
- 6.10 小结 ·····································100
- 6.11 练习题 ·······························100
- 第7 章 函 数 ········································· 102
- 7.1 数值型函数 ····································102
- 7.1.1 ABS 函数 ············································102
- 7.1.2 MOD 函数 ··········································103
- 7.1.3 SQRT 函数 ·········································103
- 7.1.4 SIGN 函数 ··········································103
- 7.1.5 CEIL 与CELING 函数 ·········································104
- 7.1.6 三角函数 ············································104
- 7.2 字符串函数 ····································106
- 7.2.1 LENGTH 函数 ·····································106
- 7.2.2 UPPER 与LOWER 函数 ······································107
- 7.2.3 LEFT 与RIGHT 函数 ···········································107
- 7.2.4 CONCAT 函数 ·····································108
- 7.2.5 TRIM 函数 ·········································108
- 7.2.6 INSERT 函数 ······································109
- 7.2.7 SUBSTRING 函数 ·······························109
- 7.2.8 REVERSE 函数 ····································110
- 7.2.9 REPLACE 函数 ····································110
- 7.3 日期与时间函数 ·············································111
- 7.3.1 NOW 和SYSDATE 函数 ·····································111
- 7.3.2 CURDATE 函数和CURRENT_DATE 函数 ·································111
- 7.3.3 CURTIME 函数和CURRENT_TIME 函数 ··································112
- 7.3.4 DAYOFWEEK 函数和WEEKDAY 函数 ·······································112
- 7.3.5 DAYOFMONTH 函数和DAYOFYEAR 函数 ······································113
- 7.3.6 MONTH 函数和MONTHNAME 函数 ········································113
- 7.3.7 DATEDIFF 函数···································114
- 7.3.8 ADDDATE 函数 ···································114
- 7.3.9 DATE_FORMAT 函数 ··········································115
- 7.4 聚合函数 ········································116
- 7.4.1 MAX 函数 ··········································116
- 7.4.2 MIN 函数 ············································117
- 7.4.3 COUNT 函数 ······································118
- 7.4.4 SUM 函数 ···········································118
- 7.4.5 AVG 函数 ···········································119
- 7.5 综合案例 ········································119
- 7.5.1 案例目的 ············································119
- 7.5.2 案例演示过程 ······································120
- 7.6 小结 ·······································121
- 7.7 练习题 ·································121
- 第8 章 使用基本的查询语句 ····································· 122
- 8.1 查询语句基础 ································122
- 8.1.1 基本语法 ············································122
- 8.1.2 使用“*”查询表中的全部内容 ····································123
- 8.1.3 查询表中指定的字段 ···········································124
- 8.1.4 使用DISTINCT 关键字去除结果中的重复行 ·················&am