随笔分类 -  mysql

摘要:• #!/bin/bash• file_name=`date +%Y%m%d%H%M%S`• db_path='/usr/local/db_back/'• mysqldump -ulepus -p123456 -A >${db_path}${file_name}_all.sql• echo "bac 阅读全文
posted @ 2016-09-29 14:24 D.零下的小书屋 阅读(155) 评论(0) 推荐(0)
摘要:创建索引的语法格式:– 创建普通索引:• create index 索引名称 on 表名(列)• alter table 表名 add index 索引名称 (列)– 创建唯一索引:• create unique index 索引名称 on 表名(列名)• alter table 表名 add un 阅读全文
posted @ 2016-09-23 17:27 D.零下的小书屋 阅读(237) 评论(0) 推荐(0)
摘要:其实就是造测试数据 eg: delimiter $$ //定义结束符号create procedure test_p11(count int)(默认是in类型)begindeclare name varchar(20);//定义变量declare phone int(20);declare i in 阅读全文
posted @ 2016-09-23 17:18 D.零下的小书屋 阅读(182) 评论(0) 推荐(0)
摘要:命令行执行mysqldump mysqldump -uuser -pPassword dbnametable [option] > xx.sql;mysqldump• Mysqldump常用参数:• --all-databases , -A 导出全部数据库• --add-drop-database 阅读全文
posted @ 2016-09-23 14:51 D.零下的小书屋 阅读(469) 评论(0) 推荐(0)
摘要:授权就是为某个用户赋予某些权限。例如,可以为新建的用户赋予查询所有数据库和表的权限。合理的授权能够保证数据库的安全。不合理的授权会使数据库存在安全隐患。 MySQL中使用GRANT关键字来为用户设置权限。Grant 命令的格式grant 权限 on 数据库对象 to 用户比如说增加一个超级用户,拥有 阅读全文
posted @ 2016-09-23 11:48 D.零下的小书屋 阅读(379) 评论(0) 推荐(0)
摘要:子查询 --1、子查询必须位于圆括号里 --2、除非主查询理有多个字段进行比较,否则子查询的select子句里只能有一个字段 --3、子查询里不能使用order by 子句。在子查询里,我们可以利用 group by实现order by 功能 --4、返回多条记录的子查询只能与操作符配合使用(如:i 阅读全文
posted @ 2016-09-23 11:20 D.零下的小书屋 阅读(280) 评论(0) 推荐(0)
摘要:使用union可以将多个select 语句的查询结果集组合成一个结果集。select 字段列表1 from table1union [all]select 字段列表2 from table2...说明:字段列表1与字段列表2的字段个数必须相同,且具有相同的数据类型。合并产生的新结果集的字段名与字段列 阅读全文
posted @ 2016-09-22 17:56 D.零下的小书屋 阅读(132) 评论(0) 推荐(0)
摘要:聚合函数: select avg(salary)//平均值 from wsb; select sum(salary)//总和 from wsb; select max(salary)//最大 from wsb; select min(salary)// 最小 from wsb; select cou 阅读全文
posted @ 2016-09-22 17:26 D.零下的小书屋 阅读(318) 评论(0) 推荐(0)
摘要:select *from wsb limit 5;显示前5行 select *from students LIMIT (m,n) +where 筛选条件 select *from wsb where salary>2000; select *from where age is null;(空字段) 阅读全文
posted @ 2016-09-22 16:00 D.零下的小书屋 阅读(962) 评论(0) 推荐(0)
摘要:update 表名 set 字段=XX where....;(记得加条件不安全改了) 多个字段: update 表名 set 字段1=XX,字段2= where....;(记得加条件不安全改了) 修改多个表的数据: update stu ,score set stu.age=18 ,score.gr 阅读全文
posted @ 2016-09-22 14:47 D.零下的小书屋 阅读(139) 评论(0) 推荐(0)
摘要:delete from 表名 删除表里的数据 可以配合where试用 阅读全文
posted @ 2016-09-22 14:40 D.零下的小书屋 阅读(134) 评论(0) 推荐(0)
摘要:1、指定字段插入数据 insert into wsb2(stu_name,salary)values ('nan','10000'); insert into wsb2(stu_name,salary)values ('nan','10000'),('cc','200');//插入多条 2、不指定字 阅读全文
posted @ 2016-09-22 14:38 D.零下的小书屋 阅读(134) 评论(0) 推荐(0)
摘要:• 语法: create table 表名(• 列名1 列类型 [<列的完整性约束>],• 列名2 列类型 [<列的完整性约束>],• ... ... ); • PRIMARY KEY 主码约束(主键)• UNIQUE 唯一性约束• NOT NULL 非空值约束• AUTO_INCREMENT用于整 阅读全文
posted @ 2016-09-22 14:13 D.零下的小书屋 阅读(169) 评论(0) 推荐(0)
摘要:MySQL存储引擎简介(针对表)存储引擎的概念是MySQL的特点,而且是一种插入式的存储引擎概念。这决定了MySQL数据库中的表可以用不同的方式存储。用户可以根据自己的不同要求,选择不同的存储方式、是否进行事务处理等。 MySQL提供了插件式( Pluggable)的存储引擎,存储引擎是基于表的,同 阅读全文
posted @ 2016-09-21 17:12 D.零下的小书屋 阅读(128) 评论(0) 推荐(0)
摘要:创建一个数据库 • 建立数据库操作: 语法: create database 数据库名 叙述:创建一个具有指定名称的数据库。如果要创建的 数据库已经存在,或者没有创建它的适当权限,则此 语句失败。 例:建立一个besttest库。 mysql> create database besttest CH 阅读全文
posted @ 2016-09-21 16:49 D.零下的小书屋 阅读(277) 评论(0) 推荐(0)
摘要:SQL语言分为三个部分:数据定义语言( Data DefinitionLanguage,简称为DDL)、数据操作语言( DataManipulation Language,简称为DML)和数据控制语言( Data Control Language,简称为DCL)。DDL语句: CREATE、 ALT 阅读全文
posted @ 2016-09-21 15:57 D.零下的小书屋 阅读(121) 评论(0) 推荐(0)