lnf0701@163.com

静默

基本操作

mysql engines:查看数据库支持的数据库;

show table status like '表名称' \G; 以列显示表信息。

ENUM:枚举(只可取一个),SET:集合(随意组合)内置类型,

show character set;显示服务器支持的所有字符集,

show collation:显示排序规则, 一种字符集或许有多种不同的排序规则,

SERIAL是BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE的一个别名

auto_inscrement == int unsigned not null primary key(必备条件:整型,非空,无符号,主键或唯一)

会话变量:show [session] variables; ---session 可以省略,

BLOB存储的是二进制字符串(字节字符串);TEXT存储的是非二进制字符串(字符字符串)。

BLOB列没有字符集,并且排序和比较基于列值字节的数值;TEXT列有一个字符集,并且根据字符集对值进行排序和比较

 BLOB是二进制字符串,TEXT是非二进制字符串,两者均可存放大容量的信息。BLOB主要存储图片、音频信息等

而TEXT只能存储文本文件。

 键也称为约束,可作索引, 属于特殊索引(有特殊的限定) B+tree

show indexes from tables_name;

create table test-table select * from tables-name where id <2;-->仿照tables-name创建一个新的表。。

alter table table_name engine=innodb; ---修改表存储引擎。

alter table student add foreign key foreign_cid(cid) references tables-name (cid) ---外键

只有innodb支持外键,不建议使用,影响性能,,

create index name_on _student on student(Name) using btree;-->创建索引名称为name_on_student 在表student 的Name字段。

create index name_on _student on student(Name(5)DESC) using btree;在text字段上必须指定长度,

索引只能创建,删除不可以修应该,。

查询方法:简单查询,多表查询,子查询:

select distinct gender from students; ---->只显示唯一的,不会有重复。

between...and...,     not(age>25 or gender='M'),,age in (19,21,24),where cid2 is null/is not null-->判断空或者不空。

where name rlike '^[xy].*$'; -----正则表达式方法,

查询后的结果排序:

order by field_name [asc|desc]; limit 3-->显示几行,

分组:主要目的就是做聚合运算:

select age,gender from students group by gender ---->根据gender来分组的,

select avg(age) from students group by gender having 过滤条件; ---->显示男女同学的平均年龄。

多表查询,

select student.name,courses.cname from students left join courses on cid1=cid;

自连接:

子查询:子查询只能返回单个值,比较操作中使用子查询,在in中使用子查询

select name from student where age in (select age from tutors);

select name from students where age > (select avg(age) from students);

联合查询:(select...)union(select....)

几个重要函数:

SELECT MOD(31,8) ---->取余数,
select avg|sum|min|max|count(age) from student --->聚合函数,

/etc/my.cnf , /etc/mysql/my.cnf ,, /usr/local/mysql/my.cnf ,,~/.my.cnf -->最后有效

服务器变量:定义服务器运行特性,show global variables
状态变量:定义服务器运行统计数据,show global status
通配符:_;任意一个单个字符。%:任意多个任意字符。

新建文件在目录/etc/ld.so.conf.d/mysql.conf << echo "/usr/local/mysql/lib"
ldconfig -v ---->重新读取库文件
头文件:
ln -sv /usr/local/mysql/include /usr/include/mysql --->头文件和库文件的定义,软件的配置。

create view ssc as select ........ show tables ----->可以查看
视图:就是存储的select语句。用作查找的虚表,drop view 删除视图,
物化视图:将视图查询的结果保存下来。
show create :显示创建对象使用的语句。

mysql -e 'select * from jiaowu.students;'
Mysql事务和隔离级别:
select * from tutors order by tid desc limit 1;

重新开始计数:truncate 表明 ---->清空表,重置计数器

posted @ 2015-12-16 19:21  lnf0701  阅读(200)  评论(0)    收藏  举报