
-7.5
修改权限
- 权限 update `user` set host=”%” where user=”root”
- 允许指定用户访问:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.10.11.12' IDENTIFIED BY 'FEFJay' WITH GRANT OPTION; flush privileges;(IP
这里,可以使用%来表示所有IP)
-
重启服务即可
8. 创建数据库
- 8.1
使用客户端软件创建数据库
- 8.2
使用命令创建数据库
- create database
数据库名
- create database
数据库名 character set utf8
- show create database
数据库名
- 8.3 修改数据库编码
- alter database
数据库名 character set utf8
- 8.4 删除数据库
- drop database
数据库名
- 8.5 切换、使用数据库
- use
数据库名
- 8.6 显示当前数据库
- select database()
- 8.7 展示所有数据库
- show databases
9. 创建数据表
- 9.1
使用命令创建数据表
- create table
表名
(
字段1
字段类型,
字段2
字段类型,
字段3
字段类型……
)
- 9.2
常用数据字段类型
-
整数

-
小数

-
字符串

-
日期时间类型


-
枚举
10.查询
- 10.1 查询数据表中全部的行和列
- select col1,col2,col3….from table
- select * from table
- 10.2 查询表的部分列
- select col1,col2,col3…from table
- 10.3 给查询出来的数据列设置别名
- select col1 as “
别名1”,col2 as ‘
别名2’…from table
- select col1 ‘
别名1’,col2 ‘
别名2’….from table
- 注意多表查询重名问题
- 10.4 DISTINCT
关键字的使用
- 作用:消除结果集中的重复数据
-
语法:select distinct col from table
- 注意:要求所有的字段都相同才会去重
- 10.5 LIMIT
关键字的使用
- 作用:指定结果的显示范围
- 语法:
- select * from table limit m,n
m
:起始的位置
n
:显示的数量
- select * from table limit m
m:
从第一条开始共显示m条数据
11. 插入数据
- 11.1 所有列都插入值
-
语法:insert into table values(v1,v2,v3….)
- 特点:列值同数,列值同序
- 11.2 为指定列插入值
-
语法:insert into table(col1,col2,col3) values(v1,v2,v3)
- 特点:指定顺序,列值对应
- 11.3 一次性插入多条记录
-
语法:insert into table(co1,col2,col3…)values
(v1,v2,v3),
(v1,v2,v3),
(v1,v3,v3)…..
12.修改数据
- 12.1 修改指定数据
-
语法:update table set {col1=value1}[…n]where expressioin
- 12.2 修改全部数据
-
语法:update table set {col1=value1}[…n]
13. 删除数据
- 13.1
使用delete
命令删除数据
-
语法:delete from table where expression
- 13.2 逻辑删除
- 13.3
使用truncate
命令删除数据
- truncate table
- 13.4
区别
-
Delete语句删除数据,自动编号没有恢复到默认值。但是truncate重新设置了自动编号
-
通过truncate语句删除数据表数据,不能根据条件删除,而是一次性删除,delete语句可以根据条件进行删除
-
truncate在清空表中数据的时候,速度要比delete语句快的多
14. 对列进行增删改查
- 14.1
增加一列
- alter table tablename add
列名 数据类型
- 14.2 删除一列
- alter table tablename drop column
列名
- 14.3 修改列的数据类型
- alter table tablename modify
列名 数据类型
-14.4 修改列的数据类型并且改名
- alter table tablename change old_colname new_colname
数据类型
15. 约束
-
问题1
:数据冗余

- 问题2:失去了完整性

- 问题3:数据缺少唯一标识

- 问题4:失去了实体完整性

- 问题5:失去了引用完整性

- 问题6:失去了域完整性