Mysqlc/sclientserver】架构(mysql5.1.pdf手册)

前期可以用rpm后期可以用源码包的编译安装.

Cat /etc/issue 查看系统版本

数据库目录 :/var/lib/mysql/ 应该是空的在第一次启动后会进行初始化下面才会有东西

数据会放在datadir

Mysql的配置文件 /etc/my.cnf

安装 mysql-server mysql-devdl(开发包)

数据存放目录

Mysql的联接 mysql  --用户名–h ip –ppassword(密码前面没有空格)默认用户名是root 这个root不是系统的root是数据库的 ,密码默认也是没有的所以可这省略.

Mysql默认只能接受本地联接

启动方式: 1 mysql

       2mysql –u root –h 127.0.0.1

Sql语句结构化查询(ibm提出的)增。删。改。查每句用;号结束。

例子: show databases;

退出方式:1 quit

        2 ctrl+c

数据的关系:data---column---table---database----global

创建库(也就是在/var/lib/mysql下创建一个目录,)你也可以在数据库外在这个目录下去创建一个目录但是要注意所属主所属组权限很重要。当然你直接登陆到数据库;create database 库名;也是一样的。

Create table databasenameTablename aa int)。在指定库中创建表

Create table a a int)在默认表中创建

查看当前位置 \S

查看表的结构:desc 表名

数据类型:int 整数型bigint大的整数型float浮点型(小数点);char(规定字符数)字符型 varchar 的区别一个是先分配空间再存放数据,一个是先计算再分配空间,但是最多也不能超过()中规定的大小。Varchar节省空间但会用到计算所以会产用cpuchar造成空间的浪费。Enum (‘a’,‘b’,‘c’)指定范围内的单选 abc set是指定范围内的多选。Date 日期型(‘2013-6-8’)time时间型(‘23:26:00’)

一个字母是一个byte 一个数字是bit 相差是8 2是几个bit是两个bit因为2进制记录为01


数学运算比较运算等于是=  !=不等于返回值是真的是1假的是0

还有逻辑运算 and or not 非表示

between区间运算:select 5 between1 and 10;

针对于空的判断比较特殊:select * from score where nameis null ;name=’null’是不对的

*代表所有的列 where 代表行

查询办理的总成绩:select  name ,math+eng+chifrom score;

                select   列名 , 列名+列名 from表名;

select name ,math+eng+chi as total from score ; as 是别名.

Select name from score where math bwteen 60 and 80; 或者是 selectname from score where math>60 and math<80; 两个都可以.

模糊查询like条件不精确时用 % 所有 _单个字符

是效率最低的查询不到万不得已最好不要用

Select * from score where name like ‘___’;名字为三个字符的

Select * from score where name like ‘%’;查询name列的所有名字

Select * from score where name likeh%’;查询nameh开头

同时MYSQL 也支持正则

Select * from score where name regexp ‘^h’;名字是h开头的

Select * from score where name regexp’^.*n$’;名字是n结尾的

函数

常用函数count用来做统计行数的

Select count*from score;统计行数

竖着相加sum统计全班的数学总数竖向相加

Select sum(列名)from score

Select sum(math) from score;

Max 最大值

Min 最小值

Avg 平均值

Mysql5.1pdfa

’ echo hello|rev 反向输出hello

排序

默认是升序,命令尾数加desc降序排列从高到底;

数学大于60分的排序

Select * from score wheremath > 60 orderby math;升序

Select * from score wheremath > 60 orderby math desc;降序

如果想查看数学的前三名只要架上limit 3ok

Select * from score wheremath > 60 orderby math desc limit 3


分组group by 列名

Select id count*from scoregroup by id