MySQL
学习mysql笔记
yorkmass☭
个人邮箱 yaoyi@tobsion.com
展开
-
MySQL基本操作
MySQL基本操作数据库操作create database 数据库名 charset=utf8;删除数据库drop database 数据库名;切换数据库use 数据库名;查看当前选择的数据库select database();表操作查看表结构desc 表名;查看当前数据库中所有表show tables;创建表 auto_in...原创 2019-08-29 21:51:54 · 132 阅读 · 0 评论 -
MySQL表中不能插入中文解决方案
在使用mysql的时候,插入中文,报错ERROR 1366 (HY000): Incorrect string value: '\xE5\x8F\xA3\xE8\x85\x94' for column 'name' at row我们可以在建表的时候带上编码:DEFAULT CHARSET 'utf8'如:CREATE TABLE `students`( `id` INT...原创 2019-08-30 15:28:19 · 1863 阅读 · 0 评论 -
MySQL连接查询案例
设计班级表,与学生表关联,并进行查询创建班级表 create table T_classes(id int auto_increment primary key not null,name varchar(10));创建学生表,设置主外键 create table T_students(id int auto_increment primary key not null,na...原创 2019-08-30 15:41:41 · 286 阅读 · 0 评论 -
MySQL基础_添加外键约束及查询
创建一个score表create table scores(id int primary key auto_increment,stuid int,subid int,score decimal(5,2));添加外键约束alter table scores add constraint stu_sco foreign key(stuid) references T_student...原创 2019-08-30 21:43:07 · 342 阅读 · 0 评论 -
MySQL查询筛选
原始数据分组聚合select gender,count(*) from user group by gender;同时满足两个条件的数据查询select name,gender,count(*) from user group by gender,name;分组后的数据筛选having对得到的分组后形成的结果集进行筛选 select gender,coun...原创 2019-08-31 17:27:31 · 3943 阅读 · 0 评论 -
MySQL连接查询
三种连接查询连接查询inner join,两个表都匹配上的数据行才出现select student.name,subjects.title,scores.score from scoreinner join students on scores.stuid=students.idinner join subjects on scores.subid=subjects.id;A i...原创 2019-08-31 18:15:00 · 231 阅读 · 0 评论 -
MySQL事务
当一个业务逻辑需要多个sql完成时。如果其中某条sql语句出错,则希望整个操作都退回。使用事务可以完成退回的功能,保证业务逻辑的正确性事务四大特征(简称ACID)原子性:事务中的全部操作在数据库中是不可分割的,要么全部完成,要么均不执行一致性:几个并行的事务,其执行结果必须与按某一顺序串执行的结果相一致隔离性:事务的执行不受其他事务的干扰,事务执行的中间结果对其他事务必须是透明...原创 2019-08-31 20:53:11 · 144 阅读 · 0 评论 -
MySQL索引
查看索引show index from table_name;创建索引(mytable是表名 ,username是字段名,length是字段长度create index indexName on mytable(username(length),...);删除索引drop index [indexname] on mytable缺点虽然索引大大提高了查询速度,同时...原创 2019-08-31 21:27:43 · 162 阅读 · 0 评论