MySQL

SQL/MySQL

事务,隔离,并发控制,锁

用户和权限

监控

  STATUS(状态)

索引类型: 查询

  VARIABLES(服务器变量)

备份和恢复

复制功能

集群

文件:

  数据冗余和不一致性

  数据访问困难

  数据孤立

  完整性问题

  原子性问题

  并发访问异常

  安全性问题

DBMS(数据库管理系统)

  层次模型

  网状模型

  关系模型

RDBMS(关系型数据库管理系统)

文件:

  表示层

    文件

  逻辑层

    文件系统: 存储引擎

  物理层

    元数据

    数据: 数据块

E-R: 实体-关系模型

关系模型:(结构化数据模型)

  关系模型

  实体-关系模型

  对象关系模型:基于对象的数据模型

  半结构化数据模型: XML(扩展标记语言)

    <name>Jerry</name>

    <age>50</age>

    name:

    age:

    gender:

    name:

    uid:

    brithdate:

    name:age:gender

    name:uid:brithdate

关系: 关系代数运算

  交集: 两个集合共有的部分;

  并集: 属于A或者属于B的;

  差集: 属于A但不属于B,属于B但不属于A的;

  补集: 全集减去集合剩下的内容;

SQL: Structure Query Language(结构化查询语言)

70
System R: SQL

Ingres, Oracle, Sybase

ANSI: 美国国家标准委员会 ansi-sql

DML: 数据操作语言

  查询,增、删、查、改;

  INSERT:增

  DELETE:删

  SELECT:查

  UPDATE:改

DDL: 数据定义语言,定义数据存储和定义,定义RDB对象、删除对象、修改对象;

  CREATE: 创建

  DROP: 删除

  ALTER: 修改

DCL: 数据控制语言

  GRANT

  REVOKE

用户访问权限

RDB对象:

  库、表、索引、视图、用户、存储过程、存储函数、触发器、事件调度器

  约束: constraint, 定义存储范围,有效范围;

    域约束: 数据类型约束

    外键约束: 引用完整性约束

    主键约束: 某字段能唯一标识此字段所属的实体,并且不允许为空,某一个字段或者某些字段组合起来它能够唯一的标识这个表中的没一个实体;

      一个表只能有一个主键

    唯一性约束: 每一行的某字段都不允许出现相同值,可以为空

      一张表可以有多个唯一键

    检查性约束: age: int(整型,4个字节,可以表示4亿)

/etc/passwd:如果每个用户的用户名都不一样,那么把用户名当作主键就可以了,我只要提到一个用户名,它就唯一标识这个文件那一行;

域约束仅能保证它不违反数据类型,但他并不能保证违反现实逻辑;

关系型数据

  表示层: 表

  逻辑层: 存储引擎

  物理层: 数据文件

数据查询和存储

  存储管理器:完成存储;

    权限及完整性管理器

    事务管理器

    文件管理器

    缓冲区管理器:要想完成数据查询、修改都要在内存中完成,不可能在磁盘上完成,需要把数据从磁盘的文件读到内存,缓冲区管理器就是管理缓冲区空间的;

  查询管理器: 解释用户查询,将查询语句转换为存储下来数据所能理解的结构,而且能将数据抽取出来或者能够实现数据存储的工具;

    DML解释器

    DDL解释器

    查询执行引擎

查询管理器有三个组件DML解释器、DDL解释器,解释的结果要交给查询执行引擎来执行,查询执行引擎提醒给存储管理器,存储管理器有缓冲区管理器、文件管理器、事务管理器、权限及完整性管理器,有那些东西可以发送查询请求,应用程序、SQL用户、程序员、DBA(专用数据库管理工具),DBA通过管理工具跟它交互,终端用户很可能通过应用程序进行交互,SQL用户通过SQL接口跟它交互,程序员通过SQL接口或者API跟它交互,由此可见我们的交互方式有许多种,但无论是哪一种就意味着两个进程之间要通信,应用程序假如是PHP应用程序,这个PHP程序要跟My SQL服务器通信,或者跟数据库管理系统通信,SQL用户它使用客户端,客户端也要跟数据库管理系统通信,他们俩之间怎么建立联系,我们此前学过的进程间通信有那些,使用管道,一个命令的输出当作另一个命令的输入,这就是通信,使用kill命令,向一个进程发送信号,这也是一种通信,kill命令是个进程,而接收这个信号的是另外一个进程,但是不能向My SQL服务器发送kill命令,似乎也没有通过管道向My SQL发送,那怎么跟My SQL交互,我们在进程间通信的时候,有服务器端和客户端这种通信,他们俩之间是建立数据交互的,有所谓的C/S架构,两个专用软件之间,一个处于被动打开状态,一个处于主动打开,一个去请求,一个去响应,一个去接收请求,解析请求,响应请求,一个是提出请求,接收响应,它俩之间怎么通信,靠协议才能通信的,客户端发送命令到服务器端,它要靠tcp/ip把请求送过去,服务器端接收下来请求之后,这里面到底是个什么语句,我们这个语句到底能不能接收下来,能不能执行,我们必须要理解用户的请求是什么,所以它也应该有My SQL协议,也就意味着客户端发出的命令必须要能够让服务器端理解而且知道它请求的是什么才行,比如要查询某个库的某张表,我们服务器压根没有这个库这张表,要告诉查询的不对,他们俩之间也要能够交互的,所以无论是应用程序也好,SQL用户也好我们要借助于组建来实现,比如DBA至少需要一个管理工具,管理工具要跟它通信,应用程序要通过我们所开发的API或者服务器链接程序通信,SQL用户用的My SQL,而程序员使用API,也是服务器输出的API,它一定要监听在服务器某个套接字上,能够接收用户请求才可以,如果多个用户同时连进来怎么办,就像Web服务器一样,多个请求同时进来怎么办,一个进程响应一个,一个线程响应一个,一个线程响应多个,反正不管怎么讲我们必须要在内部完成这种机制,而且能够区别每个请求,对于My SQL而言,我们能不能让一个进程响应多个,或者能不能让一个线程响应多个请求,像Web服务器一样,像event模型,或者nginx一个线程响应多个请求,My SQL行不行,如果一个用户发起SQL语句查询一张表,而另外一个用户也发起同样的SQL语句,于是让它用同一个线程来响应,那就意味着第一个用户请求的第二个用户直接能够得到结果,但是第二个用户就没有这个访问权限呢,数据库安全性无从得到保证,所以一般来讲数据库是不允许一个线程响应多个请求的,为了避免权限交差,所以一般是一个线程响应一个请求,而我们的My SQL就是这种模型,它为每一个用户连接生成一个线程,一个独立的线程,而这个用户发起的所有请求,查询、修改、删除等等都在这个线程内部完成,也就意味着My SQL是单进程多线程的,My SQL只有一个服务器进程,但它是多个线程的,它的线程有很多种,有守护线程,My SQL自己内部运行的线程,可以理解为守护线程,也有应用类型,守护线程,比如My SQL在它背后完成将数据从缓冲区管理器写到磁盘上去,我们必须要定期的将数据从内存写到磁盘上去,不然掉电数据会丢失的,这些都要靠我们的My SQL进程后面自己来完成,应用线程,一个用户请求进来用户退出了就没有了,所以它内部的线程有很多个,一般来讲一个用户请求都有一个线程,事实上一个My SQL内部线程数量非常大的,尤其是并发用户的时候,还要考虑一个问题,假如连接进来两个用户,或者连接进来十个用户,第一个用户发起查询请求,这个查询请求需要往内存中载入,它发起很大的查询,需要载入256M的数据才能完成,第二个用户请求需要载入1G的数据才能完成,第三个请求需要载入256M数据才能完成,这十个用户就要占据大量内存,所以由于My SQL的操作涉及的数据量是非常大的,可能它的并发能力跟我们此前所理解的Web服务器是不一样的,Web服务器请求一个页面,一般来讲一个页面最大不是下载服务器不会特别大,但对My SQL不是如此,用户请求进来一个查询语句可能会涉及到1G的数据操作都有可能,所以它的并发能力不像想象那样子,像Web服务器那样,因此一个数据库服务器通常是系统性能的最慢的节点所在,所以应该尽可能避免跟数据库交互,怎么避免跟数据库交互,怎么能够提高数据库的交互速度-缓存,尽可能将数据第一次操作以后给它缓存到用户的门口,第二次再访问的时候直接使用这个结果就可以了,假如数据库服务器非常繁忙,作为应用程序来讲,作为discuz来讲,用户一会发个帖子一会发个帖子,每一次发一个新帖就都是一个新的请求,对于My SQL服务器来讲,或者对于后端的数据库服务器来讲,每一个用户请求都要有一个线程来响应,那就意味着我要创建一个线程执行请求,撤销线程,创建一个线程执行请求,撤销线程,如果对于一个非常繁忙的服务器来讲,我们线程创建、撤销,创建、回收...也要消耗大量资源,怎么能够加速,线程重用,一个用户退出以后这个线程空闲下来,空闲以后不删了,放在空闲线程池里面,以后用户请求直接拿空闲线程去响应它,不管怎么来讲无论是线程重用还是缓存无非就是让数据库系统执行的速度会更快,My SQL是单进程多线程的系统,这意味着My SQL不会为任何多个请求启动多个进程,它只会启动线程,在一个所谓的计算机体系结构上每一个进程所能够使用的地址空间是有限的,比如X86的32bit系统上,一个进程可以使用2.7G左右,My SQL在一个32bit系统上最懂只能使用2.7G内存,一个查询1G,一个大的查询,三个查询My SQL就崩溃了,它又不能启动多进程,所以再大的空间,物理主机上就算有256G的内存,但是装的32bit系统,一个My SQL进程最多使用2.7G内存,再多没用,它用不了,所以在生产环境中,一定要上64bit系统,64bit系统My SQL可以使用多大内存看软件本身能力,一般使用64G、32G内存问题不大,早期My SQL设计就是工作在小型环境中的,现在已经被极大的扩展了,但是它所能够使用的内存量仍然是有限的,更何况到今天为止My SQL仍然有个巨大的缺陷在于它对于SMP(对称多处理器)能力也是很有限的,My SQL的一个查询语句只能在一颗CPU上执行,如果一个查询非常大,如果把一个查询给它解构下来,分解开来在16颗CPU上同时完成,这样速度会很快,但My SQL不行,My SQL一个语句只能在一个CPU上执行,当同时发起10个语句,它可以在10个CPU上执行,这是没有问题的,但一个单独的语句只能在一个处理器上查询,这仍然是目前My SQL的可扩展能力的缺陷,当然Oracle为什么那么强,程序开发本身的自身的缺陷有时候导致它的扩展能力是受限制的,但尽管如此我们也可以把My SQL做分区,把一个服务器上的My SQL做减弱一点,用100台服务器组合起来完成一个任务,做一个服务器农场,一个服务器只完成一点工作,最后把它组合起来,这种处理能力是无与伦比的,所以人们总是在一个层次上扩展不了的时候,在上面加一个中间层来实现额外的扩展;

单进程

  多线程

    守护线程

    应用线程

Thread reuse(线程重用)

32bit:

  2.7G

64bit:

  smp: 对称多处理器

关系型数据库管理系统体系结构:

首先上面是查询处理器,底下叫存储管理器,再往下就是磁盘,真正实现数据存储的位置,在查询管理器上面能够接近查询管理器的有应用程序、SQL用户、程序员、DBA四类,而查询管理器里面应该接受用户的请求,接收用户请求以后,或接收来自前端应用程序请求以后怎么处理,DML解释器、DDL解释器、查询执行引擎,事实上还有缓存,除此之外底下的缓冲区管理器、文件管理器、事务管理器、权限和完整性管理器,无论是那种管理器最终这个数据要对应到磁盘上去,保存到磁盘上什么文件,数据要保存到磁盘上,那索引呢,也要保存文件,就像apache服务器一样,每个用户请求结束了要保存日志的,它也需要日志文件等等,这就是它的层次结构;

关系运算:

  投影: 只输出制定属性,只选择某些字段显示的;

  选择: 只输出符合条件的行,只选取部分行的;

  自然连接: 具有相同名字的属性上所有取值相同的行,两张表上各指出一个字段,这两个字段如果值相等就把它连接起来输出结果;

  笛卡尔积:

    (a+b)*(c+d)=ac+ad+bc+bd

  并: 集合运算,两个关系组合起来彼此都有的部分;

SQL查询语句:

  sequel--SQL

    SQL-86

    SQL-89

    SQL-92

    SQL-99

    SQL-03

    SQL-08

SQL语言的组成部分:

  DDL: 数据定义语言

  DML: 数据操作语言

  完整性定义语言: DDL的一部分功能

  视图定义:

  事务控制:

  嵌入式SQL和动态SQL:

  授权: DCL

使用程序设计语言如何跟RDBMS交互

  嵌入式SQL: 与动态SQL类似,但其语言必须程序编译时完全确定下来;

    ODBC:让非语言跟数据库进行交互语句,里面嵌入的不是SQL查询语句,而是ODBC自己函数内置的查询逻辑;

  动态SQL: 程序设计语言使用函数(mysql_connect())或者方法与RDBMS服务器建立连接,并进行交互;通过简历连接向SQL服务器发送查询语句,并将结果保存至变量中而后进行处理;

    JDBC(JAVA数据库系统互联):JAVA程序连接到服务器的应用程序接口,能够跟我们的服务器使用函数方式建立连接并进行交互接口

嵌入SQL和动态SQL的最大区别是动态SQL发送的直接是语句,而在嵌入SQL里面每一个查询机制我们必须还要使用变量等来保存许多数据的,不像简单的SQL语句就能完成了;

My SQL体系结构:

首先既然作为服务器用户的请求进来之后,我们必须要能够接收用户请求并理解用户请求,所以前端有连接管理器的组建,用于接收并解析用户请求的,它主要是接收处理用户请求,所以连接管理器接收下来用户请求以后将用户的请求转交给解析器,由解析器来完成分析,词法分析、语法分析,看能不能执行,转交给解析器来解析,解析完成之后如果发现用户的命令此前做过查询,而且查询结果有缓存的话,那就会交给缓存器,直接从高速缓存中返回结果,如果缓存中没有结果,解析器要把解析的结果直接交给查询优化器来实现优化,解析器用来将语句生成执行树,一个SQL语句执行逻辑可能有很多种,比如有三个索引,根据第一个索引能完成查询,根据第二个索引也能,根据第三个也能完成,很显然这三个索引查询结果所消耗的代价可能是各不相同的,所以经过生成解析树之后,由优化器来选择一个最佳执行逻辑,并执行最佳的语句,所以解析树生成以后,会选择一个最佳执行路径,由优化器再完成语句重写等各种额外的逻辑让它的执行效率会更高,这种就称为优化器,而优化器优化以后接下来要交给执行引擎执行,而执行引擎最终的执行操作要交给My SQL的存储引擎来完成,存储引擎将物理逻辑转换成表示逻辑,将物理层转换成表示层,物理层其实是逻辑层,所以无论如何经过优化器优化以后它要完成表查询,而最终查询的结果肯定来自于文件中存储的数据,而存储引擎所结合的就是我们真正的存储在磁盘上那些文件,文件有数据文件、索引文件、日志文件,所以连接管理器接收用户请求,如果发现此前查询过从缓存中直接返回,如果缓存中找不到合适的逻辑,于是交给解析器,解析以后有可能还会发现缓存中有结果,解析以后也有可能从缓存中返回,但是解析以后发现缓存中也没有,交给优化器优化,优化以后要执行了,要交给存储引擎进行执行,但是注意的是My SQL的存储引擎比较独特,My SQL是插件式的存储引擎,存储引擎是个程序负责将表示层转换成物理层,这种转换机制事实上是靠软件来完成的,就像文件系统本身也是软件,这个软件本身不同组织所开发的转换机制可能各不相同,My SQL为了支持更灵活的架构,它把存储引擎做成插件式的了,任何额外第三方都可以开发自己的插件来用于存储引擎,完成从物理层到表示层的转换,从表示层到物理层的转换,这种双向转换,由此Oracle只有一个存储引擎,所以从来没有关心过存储引擎,而SQL Server也是,但是My SQL却有多种不同的存储引擎,而其实它的各种高级操作,比如事务、锁都是在存储引擎层完成的,所以不同的存储引擎它所支持的特性是不一样的,有的存储引擎不支持事务,有的存储引擎对事务支持非常的好,My SQL可以允许我们自由选择使用哪一种存储引擎,但Oracle不支持,所以这是My SQL非常独特的地方,它支持插件式存储引擎,而且My SQL安装完以后,它给我们附带的存储引擎有很多种,不同的存储引擎支持不同的特性,而且它有些特性是非常独特的,可以完全应用在非常独特的场景当中以实现高级功能,连接管理器还可以划分连接管理器,很显然连接管理器主要负责监听在某个套接字上并接收用户请求的,一旦用户请求被接收下来,一个用户请求要靠一个线程来响应,所以它需要一个线程管理器负责给用户创建生成新的线程,或者完成线程重用的方式给用户一个响应线程,所以还需要线程管理器,所有的用户请求都是先发往连接管理器的,发进来之后由连接管理器接收,使用线程管理器给它生成线程进行处理,而后一旦处理接受之后用户连接进来了,接下来检查用户有没有连接权限,用户模块管理用户是否能够连接,权限管理第一关,如果用户不能请求用户就终止了,用户请求结束了,连接也结束了,它退出了,也终止,所以用户模块还负责退回用户,一旦用户通过认证了,也就意味着它有权限连接进来,接下来要发SQL语句,一般来讲执行SQL语句,每一个SQL语句要进行分析,DML有DML的解析器,DDL有DDL解释器,不同的语句我们要分析以后给它派发给不同的解析器的,接下来又有一个模块叫命令分发模块,看什么类型的命令分发到对应的解析器上去,命令分发之前,比如是查询语句在分发之前它有可能要检查缓存,如果是查询语句,而且缓存中有内容,从缓存中就直接返回结果了,同时用户发起命令之后,像Web服务器一样,用户请求任何一个资源应该记录日志,所以命令分发模块还有可能跟日志模块进行交互,用于实现记录用户查询的,或者完成用户查询当中的某些事务,或者跟查询逻辑相关的某些日志操作,所以它还有可能给我们日志子系统进行交互,叫做日志模块,如果不需要跟缓存交互,它也有可能需要跟日志模块交互,这两个并非是并行的,但不管怎么讲日过缓存没有接下来就要将命令分发出去,将命令交给解析器,命令分发模块交给解析器,由解析器最终判定它是属于那一种语句,解析器解析以后发现这是一个SQL语句,任何查询操作还要经过优化器进行优化,所以解析器要交给优化器,如果是SQL语句要交给优化器,如果是update、delete、insert语句要交给表定义模块,我们删除某个表中某个字段的某个数据,如果这个表中没有这个字段就删除不了,必须要检查用户的所操作的跟表相关的数据本身表中是不是有对应逻辑的,还要检查用户有没有权限,要删除某个表中的某个字段数据有没有权限删除,所以这个是用来完成认证的,这里还要检查用户的权限,所以叫表定义模块,这是跟修改相关的语句,此外还有一个模块叫修复模块,仍然是跟表维护模块相关的,不叫表定义叫表维护模块,My SQL还有一些叫repair语句是用来修复表中的某些逻辑错误的,所有有表维护模块来响应用户的修复请求,My SQL还有众多的存储状态信息,叫状态变量,这些状态变量也需要进行维护,它需要状态报告模块来存储每一个执行过程当中的状态信息,My SQL还有复制,就像DNS服务器一样主服务器建立的数据它应该定期同步到从服务器上,所以复制模块,无论是那一个模块用户最终要完成操作必须要检查用户有没有权限,所以表定义模块、表维护模块都需要检查用户的权限,要删除内容如果用户没有删除权限怎么办,由于考虑到这些几乎都可能用到用户权限检查,所以他们最终都要交由用户访问模块再来进行控制,来检查用户特定的操作有没有相应的操作权限,如果访问控制模块通过解码以后没有任何问题接下来要交给另外一个组建叫做表管理器,由表管理器完成真正意义上的操作,表管理器交由存储引擎接口,接下来交给MyiSAM或InoDB了,连接管理器用于侦听来自于客户端的连接,然后将请求派发给线程管理器,所以连接管理器就是个侦听器,让服务器初始化完成以后处于被动打开状态,能接收用户请求,线程管理器负责跟踪用户线程,确保每一个用户请求都能够分配到线程,而且在用户退出以后这个线程要么让它能够变成空闲进程分给其它用户后续的新请求或者是销毁此进程,所以这是用来实现处理客户端连接请求模块,叫线程管理器,用户模块主要用来验证用户身份的,My SQL是用户名加@主机的方式,所以用户向服务器发起连接的时候你到底有没有权限连接,有没有访问权限,因此用户访问模块就是来验证用户身份的,访问控制模块,用户连接只是看用户连接访问身份,能连接进来并不意味着对每一个数据库都能操作,对每一个表都能操作,所以访问控制模块用来验证用户是否真正具有权限操作其想操作的对象,或所请求的操作的,访问控制模块来检验客户端用户是否具有足够的权限来执行所请求的操作,解析器查询并生成解析树,一旦解析树生成以后接下来要将用户请求的解析语句生成的解析树交给特定的模块来进行完成,比如纯查询语句交给优化器,修改DML的语句交给表定义模块等等,包括DDL的语句,命令调度器,命令分发模块你这个命令直接由缓存直接返回结果,还是交由解析器,如果用户请求压根就不涉及到解析器,仅仅是请求状态信息,只需要记录下日志就可以了,并非所有的SQL语句都要交给解析器,日志模块主要用户记录日志的,命令分发模块主要完成命令分发,决定怎么交给底层模块来进行实现进一步处理的,优化器负责创建响应请求时候的最佳查询策略,执行树有N条,选择其中一条以后,这条执行的过程它也可能有多种不同的逻辑,优化器就负责将这个逻辑给它转换为在服务器上执行的开销最小速度最快执行模式,所以优化器对任何一个关系型数据库都是最关键的模块,服务器性能到底如何在一定程度上取决于优化器,表管理器用户通过表定义模块创建一张表,这张表最终要存储到存储引擎上,表管理器就将表的定义转换成对应的文件的,表管理器负责创建、读取、修改表定义文件,维护表描述符高速缓存,比如要删除一张表,当前数据库有没有这张表,当前库中一共多少张表,都需要自己定义,很多的操作都是针对表来进行的,所以我们必须要确保表要能够随时随地的被访问到,而表本身都是存储在磁盘上的,包括表的结构,所以如果每次访问一张表都要从磁盘上载入的话速度太慢了,由此需要将表的定义表的名称给它缓存在内存当中,这就叫表描述符高速缓存,一般一张表被访问以后它的结构都会被缓存到内存里面,以后再访问都在内存中完成,另外还要管理表锁,一个用户正在修改表中的数据,其它用户就不能查询,发起一个select语句针对某张表,这张表首先被打开,这个表中有多少字段,每个字段的结构,都要被My SQL服务器能访问到,由此这个过程一个select语句运行之后,我们必须open这张表,把这个表的结构载入到内存里面,由管理器进行分析,接下来如果用户所查询这个字段存在,而且用户都有权限,接下来的完成过程才有表管理器交给对应的存储引擎去查询真正的数据的,当用户需要连接到数据库上来完成某种操作的时候,首先发起连接请求,由连接管理器负责接收用户连接请求,并且将用户连接请求转发给线程管理器,给它创建一个线程,一个新的线程响应用户请求,然后由线程管理器创建完线程以后,将线程的控制权限转交给用户模块来验证用户请求的内容是不是有相应的访问权限,如果没有就终止,如果有连接就建立了,而后用户后续发起查询语句,连接建立后可能就发起命令了,由命令分发模块来完成用户请求的内容是不是缓存中直接返回,要不要记录日志,如果缓存中没有,很可能这个语句需要解析转交给解析器进行分析,生成执行树,并交由底层的对应模块来处理,如果用户要发起select语句就要使用优化器来生成更优的执行过程,如果用户发起的是表的定义相关模块,就是跟表修改或者跟数据相关的功能都要交由表定义模块或表修改模块,比如insert、update、delete甚至create一张表等等,都需要有表定义模块或表修改模块来进行维护,如果用户需要修复或维护一张表,比如修理一下表做下碎片整理,这时候还要通过表维护模块来完成,很显然用户的每一次操作我们也发起select语句,这时候状态信息要更新,我们的查询请求又多了一个,状态报告模块负责更新用户每一次请求操作,最终用户无论是哪一种请求都要判定用户到底有没有对应的访问权限,于是由访问控制模块来完成权限检查,如果用户请求的权限有,由表管理器负责后续的动作,比如读取表结构,修改表结构,以及施加表锁等等,都由表管理器来完成,最终要完成执行操作了,那就由存储引擎负责到对应的数据文件中去找对应的数据,所以存储引擎才是真正跟磁盘上数据打交道的接口;

MySQL插件式存储引擎

  5.5.8: MylSAM,不支持事务;

  5.5.8后: InnoDB,支持事务,工作类似Oracle;

表管理器:负责创建、读取或修改表定义文件;维护表描述符高速缓存;管理表锁;

  表结构定义文件

表修改模块: 表创建、删除、重命名、移除、更新或插入之类的操作;

表维护模块: 检查、修改、备份、恢复、优化(碎片整理)及解析;

行: 定长,变长

文件中记录组织:

  堆文件组织: 一条记录可以放在文件的任何地方;

  顺序文件组织: 根据"搜索码"值顺序存放;

  散列文件组织:

表结构定义文件,表数据文件

表空间: table space

数据字典: Data Dictionary

  关系的元数据:

    关系的名字

    字段名字

    字段的类型和长度

    视图

    约束

    用户名字,授权,密码

缓冲区管理器:

  缓存置换策略

  被钉住的块

数据到底是如何存储在磁盘上的:

一个表中可能有很多行,最终这些行要存储在磁盘上,而磁盘上的文件系统又分为数据块,一个块到底能存储多少行数据,对于不同的表来讲,它能存储的行是不一样的,有的表的字段少,有的表的字段多,而有的表的字段,使用varchar还是可变长的,使用char类型是定长的,给50个字节,无论占用多少字节这50字节都是你的,如果一个表中的行都是定长的,那么很显然一个块中能存储多少行事先能确定,如果是变长不能确定,最终我们的数据要存储系统上的文件里面,我们将来要查询一些行的时候到底去读取那些数据块加载对应的行,怎么知道那些行存储那些块里面,用户查寻某个符合条件的行,而我们通过各种机制发现这个行位于第二个数据块上,我们是只读取这个数据,这行的数据,还是把这个数据块都读到内存里面去,这个过程就是I/O操作,将磁盘的数据读取到内存当中,而磁盘是块设备,既然是块设备,不能一次只读取一点数据,按块进行加载,所以无论读多少数据,如果这个数据在一个块中存下来了,这一行,而这一行甚至还存有其它行,事实上它也不可避免要把这块都要加载进内存当中去,块设备只能按块读取,我们要加载一个数据只能把这一块加载进去,因为它不是字符设备不能按需要读取某一个字符,所以必须要把整个块载入内存,在内存中再做进一步处理的,最终用户在表中所存储的行,有可能行是定长的,有的行是变长的,假如说一个块中可以存储4个行,或者存储10个行,时间一长可能变成10行存满要分配另外一个块,过段时间删除两行会出现碎片,将来再往里面插入新的行,是在后面开辟新块,还是存储到缝隙当中,如果是定长只要插入里面,如果是变长就麻烦了,一行空间未必能存储下来新行,如果这些空隙都不用的话,那数据库时间长了就变成了碎片化了,大量的碎片出现,出现碎片装载速度慢,有时候删除完以后把它变成紧密方式,把每一行往前挪动,后面就出现很多空隙,对于磁盘把数据都挪一挪要涉及大量的I/O操作,显著降低效率的,怎么知道一个块中空闲多少行,所以为了能够管理这样数据,一般这个块还要块头,块头里面保存了这一个块里面包含了多少行,中间有没有空白,这些空白之间都位于什么位置等等都要记录下来,文件系统的块组,块组当中定义了块组当中有多少空闲块,有多少已用块,而且还有块位图,标识那些块是空闲块,那些块是已用的,这个块按道理讲应该是磁盘块,事实上存储引擎提供了更高级的存储管理工具,所以在存储引擎还可以实现在磁盘块基础上再实现了数据固块,我们这里提到的块未必都是磁盘块,我们可以把多个磁盘块组织成一个数据块,比如4个磁盘块,一个块是4K,于是把4个磁盘块组成了16K叫做data block,而数据块是由Storage Engine(存储引擎维护管理),数据最终存储在磁盘上的结构比我们想象的可能要复杂很多,而且是定长行的表的数据查询起来执行速度块,还是变长的速度快,定长的快,所以一般不到万不得以,尽可能使用定长表结构,因为它执行速度是太快了,这是数据库优化一种逻辑,如果一个表中的字段有些数据插入量太大了,有的需要100个字节,有的需要1个字节,这时候变长也不得不采取,因为会浪费大量空间;

The MySQL RDBMS

MySQL is a relational database management system(RDBMS) that runs as a server providing multi-user access to a number of databases

MySQL is officially pronounced /maIeskju:el/("My S-Q-L"),but is often pronounced /maIsi:kwel/("My Sequel"). It is named for original developer Michael Widenius's daughter My.

The MySQL development project has made its source code available under the terms of the GNU General Public License, as well as under a variety of proprietary agreements

MySQL is owned and sponsored by a single for-profitfirm,the Swedish company MySQL AB, now owned by Sun Microsystems, a subsidiary of Oracle Corporation

Mont, TcX, Unireg, SQL

  Unireg, SQL

  MySQL AB

  96,MySQL,solaris

Speed(高性能)

  安全多线程

  查询缓存

Reliability(稳定性)

Scalability(伸缩性)

Ease of use(易用)

Portability and Standards Compliance(可移植性和标准的兼容性)

Multiuser Support(支持并发多用户同时连接请求数据)

Internationalization(国际化)

Wide Application Support(支持多的开发语言)

  C,C++,Java,Perl,PHP,Python,Ruby

  JDBC,ODBC,.NET

Open Source(开源)

The MySQL RDBMS

The roots of MySQL server are found in a database system called Unireg that was developed by Michael "Monty" Widenius for a Swedish company called TcX during the 1980s

The initial release of MySQL server was created in 1995 when Monty added an SQL interface to Unireg

David and Monty,together with Allan Larsson,founded MySQL AB in 1995.

MySQL Server Timeline(版本)

Product family(产品族)

MySQL Server(mysqld, mysql)

MySQL Cluster(集群)

MySQL Proxy(代理)

MySQL Administrator(管理)

MySQL Query Browser(查询浏览器)

MySQL Workbench(工作台)

MySQL Migration Toolkit(移植工具箱)

MySQL Embedded Server(嵌入式服务器)

MySQL Drivers and Connectors(驱动和连接器)

Community and Enterprise server versions(社区和企业版)

In August of 2007 MySQL AB began offering th MySQL server in two different versions:

  MySQL Community

  MySQL Enterprise

Contribute to MySQL server

  Blogging(博客)

  Mailing lists(邮件列表)

  User groups(用户足)

  Documentation(文档)

  Code(代码)

  MySQL Magazine(杂志)

MySQL ->

MariaDB

Percona

MySQL安装:

  专用软件包管理器包

    deb, rpm

    rpm:

      RHEL(Oracle Linux), CentOS

      SUSE

  通用二进制格式包

    gcc: x86, x64

  源代码

    5.5, 5.6

    cmake(跨平台编译)

Before Installation

Source code installation and binary file installation?

Problems with Vendor-Supplied Packages

  Some vendor-supplied packages may not include all the features and bug fixes,because the packaging process does not necessarily include all the documented changes.

Choosing the MySQL version

  GA(General Availability) 可用版

  RC(Release Cadidate) 发行候选

  beta 内测

  alpha 公测

Installing from an rpm file on GNU/Linux

MySQL RPM Packages

Installing from an arcnive package on Unix

MySQL Server Archive Package Directories

Initial Configuration

After installation, mysqld must be initialized and configured

Many MySQL programs, including mysqld, use a central configuration file to allow a database administrator to set various parameters that will persist across reboots

  The MySQL configuration file is used for many MySQL programs, including mysqld

  This centralized configuration file allows control of the behavior and characteristics of MySQL

  Different MySQL programs use options from different directives in the configuration file

    For example, mysqld uses options under the [mysqld] directive. Client programs such as mysql and mysqladmin use options under the [client] directive

  This configuration file is also known as an option file, because it contains options and their values

mysqld --defaults

On startup, mysqld looks for this configuration file in several locations

This is done in a specific order, On Unix-based systems the following order of precedence is used:

  /etc/my.cnf

  /etc/mysql/my.cnf

  $MYSQL_HOME/my.cnf

  /path/to/file when defaults-extra-file=/path/to/file is specified

  ~/.my.cnf

Even if the server finds a configuration file in the first location it will still check each location for a configuration file(每一次服务器启动都会检查每一个配置文件)

If more than one file is located, all option files are used by the server.(如果在多个地方都找不到文件,这多个文件合并起来最终结果就是MySQL配置结果)

If more than one file has the same option, the last option read is used(如果在多个文件当中有些信息是重复的,最后读取的配置为最终生效的结果)

$MySQL_HOME refers to an operating system user environment variable.

If it is not set, MySQL programs will set it to be the same as the base directory(basedir) by default, unless there is a my.cnf file in the data directory(datadir), in which case the data directory will be used.

The defaults-extra-file is used to specify an additional localtion of a configuration file.It is passed as an argument when beginning start-up of the mysqld binary.

  mysqld_safe --defaults-extra-file=/etc/mysql/my_instance.cnf(指定使用的配置测试文件)

Initial Configuration files on Windows

With Windows servers the following order of precedence is used:

  %WINDIR%\my.ini, %WINDIR%\my.cnf

  C:my.ini, C:\my.cnf

  %INSTALLDIR%\my.ini, %INSTALLDIR%\my.cnf

  /path/to/file when defaults-extra-file=/path/to/file is specified

MySQL Post-Install Configuration on Unix

Setting initial passwords

  All initial accounts are created without passwords

  With Unix-based servers a total of five users are created by the mysql_install_db script

    There are three root accounts: root@127.0.01, root@localhost, and the root@hostname(三个root用户)

    Two anonymous user accounts:' '@localhost and ' '@hostname(两个匿名用户)

Root user password assignment(给root用户设置密码)

  # mysqladmin -u root password 'new-password' -p(更改用户密码,-u制定用户,password子命令,-p原密码)

  # mysqladmin -u root -h this_host_name password 'new-password'

Another way

  You have two methods of doing this manually: executing the SET PASSWORD command or executing the appropriate UPDATE statement followed by a FLUSH PRIVILEGES statement

    mysql> SET PASSWORD FOR 'root'@host_name' = PASSWORD('new_password');(设置root@host_name用户密码)

  OR
    mysql> UPDATE mysql.user SET Password = PASSWORD('new_password')

    WHERE User = 'root' and Host='mysql.a.org';(更新mysql库user表的password字段,条件User为root,并且Host为mysql.a.org)

    mysql> FLUSH PRIVILEGES;(重读授权表)

MySQL用户密码修改:

1、# mysqladmin -u USERNAME -h HOSTNAME password 'NEW_PASS' -p(在命令行直接更改mysql用户密码)

2、mysql> SET PASSWORD FOR 'USERNAME'@'HOST' = PASSWORD('new_pass');(在mysql接口内设置用户密码)

3、mysql> UPDATE mysql.user SET PASSWORD=PASSWORD('new_pass') WHERE CONDITION;(修改密码后需要通过FLUSH PRIVILEGES重读授权表)

Anonymous users(匿名用户)

  Anonymous users are user accounts with a username of an empty string('')

  It is a best practice to drop the anonymous users because there is very rarely any valid reason to retain these accounts

  mysql> DROP USER ''@localhost;(删除匿名用户)

  To ensure that you have dropped all anonymous users,run the following query:

    mysql> SELECT user.host.password FROm mysql.user WHERE user='';

MySQL安装:

  源码安装MySQL

    cmake

字符集:

  人: 00100110 00101010

  人: 10101011 10010001

汉字: 字符集

  GBK

  GB2312

  GB18030

  UTF8

排序规则:

性能分析

mysql --> mysqld

  Unix

    mysql --> mysql.sock --> mysqld

  Windows

    mysql --> memory(pipe) --> mysqld

不再同一主机上,基于TCP/IP协议

mysql

  -uroot -h172.16.100.1

General MySQL Architecture

MySQL operates in a networked environment using a client/server architecture

In other words, a central program acts as a server, and various client programs connect to the server to make requests

A MySQL installation has the following major components:

  MySQL Server,or mysqld, is the database server program(服务器端程序)

  Client programs(mysql客户端程序)

  MySQL non-client utilities(非客户端组建)

MySQL Server

MySQL Server, or mysqld, is the database server program

The server manages access to the actual databases on disk and in memory

MySQL Server is multi-threaded and supports many simultaneous client connections

Clients can connect via serveral connection protocols

Client programs(mysql客户端程序)

For communicating with the server to manipulate the information in the databases that the server manages

MySQL AB provides several client programs.The following list describes a few of them:

  MySQL Workbench and MySQL Administrator are graphical front ends to the server

  mysql is a command-line program that acts as a text-based front end for the server.It's used for issuing queries and viewing the results interactively from a terminal windows

  Other command-line clients include mysqlimport for importing data files,mysqldump(备份工具) for making backups,mysqladmin(管理工具) for server administration,and mysqlcheck(检查数据库完整性工具) for checking the integrity of the database files

MySQL non-client utilities(mysql非客户端组建)

These are programs that act independently of the server.

They do not operate by first establishing a connection to the server.myisamchk(检查修复myisam表) is an example.It performs table checking and repair operations.
Another program in this category is myisampack(压缩myisam表),which creates compressed read-only versions of MyISAM tables.

Both utilities operate bye accessing MyISAM table files directly, independent of the mysqld database server.

If there are no protocol, soket, host, or port options given, a socket file will be used for connecting(如果没有指定协议,soket, host, port都没有指定,默认使用socket)

If a port option is given and no host or protocol options are given, a socket file is used to connect(如果只指定端口,没有主机或协议,端口被忽略,仍然使用socket)

If the protocol specified is TCP, the connection will be made via TCP/IP even if socket option is given (如果指定使用tcp,连接就要使用tcp)

If the protocol specified is SOCKET and a port is given but no host is given, a socket file is used to connect(如果协议指定为SOCKET,但又给定端口,没有给主机,端口没意义,)

If the protocol specified is SOCKET and the host option localhost is given, a socket file is used to connect(如果协议指定为SOCKET,主机也指定为localhost,那一定使用socket)

If the protocol specified is SOCKET and a host option other than localhost is given,an error occurs (regardless of whether a port option is given) (如果协议指定SOCKET,但是一个主机指的是非localhost,那出错了)

If the host, port, and socket options are all given but the protocol option is not, the host and port are used

MySQL客户端工具:

  mysql

  mysqldump(备份工具)

  mysqladmin(管理工具)

  mysqlcheck(检查数据库完整性工具)

  mysqlimport

  [client]

  -u USERNAME(指定用户名)

  -h HOST(指定主机)

  -p ''(指定密码)

  --protocol {tcp|socket|pipe|memory}

  --port PORT


  --user

  --password

  --protocol(指定使用协议,协议只有tcp)

    tcp(远程连接)

    socket(unix)

    pipe(windows)

    memory(windows)

  --host

  --port(指定短裤)

  --shared-memory-base-name

  --socket

MySQL非客户端工具

  myisamchk(检查修复myisam表)

  myisampack(压缩myisam表)

MySQL存储引擎:

MyISAM

  每表三个文件:

    .frm: 表结构

    .MYD: 表数据

    .MYI: 表索引

InnoDB: 管理方式有两种,默认情况下,它的每一个表都有表结构定义文件,但是表数据放在表空间的一个单独文件当中的,只要是使用InonoDB存储引擎的,所有的表它的表数据都放在同一个文件里边叫做表空间,但这种方式并不是特别好,所以一般建议可以定义InnoDB使用为每一个表也使用一个单独的表空间文件,所以它可以支持;

  所有表共享一个表空间文件(这种方式不支持后来很多高级特性);

  建议: 每表一个独立的表空间文件(特性默认没有打开);

    .frm: 表结构

    .ibd: 表空间(表数据和表索引)

    .opt: 当前数据库默认字符集和排序规则的定义,数据库的选项

编译安装MySQL-5.5

cmake的重要特性之一是其独立于源码(out-of-source)的编译功能,即编译工作可以在另一个指定的目录中而非源码目录中进行,这可以保证源码目录不受任何一次编译的影响,因此在同一个源码树上可以进行多次不同的编译,如针对于不同平台编译。

编译安装MySQL-5.5

一、安装cmake

跨平台编译器

# tar xf cmake-2.8.8.tar.gz

# cd cmake-2.8.8

# ./bootstrap

# make

# make install

二、编译安装mysql-5.5.25a

1、使用cmake编译mysql-5.5

cmake指定编译选项的方式不同于make,其实现方式对比如下:

./configure cmake .(配置)

./configure --help cmake . -LH or ccmake .(帮助)

指定安装文件的安装路径时常用的选项:

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql(指定mysql默认安装路径)

-DMYSQL_DATADIR=/data/mysql(数据文件路径)

-DSYSCONFDIR=/etc(配置文件路径)

默认编译的存储引擎包括:csv、myisam、myisammrg和heap。若要安装其它存储引擎,可以使用类似如下编译选项:

-DWITH_INNOBASE_STORAGE_ENGINE=1(使用innobase存储引擎)

-DWITH_ARCHIVE_STORAGE_ENGINE=1(使用archive存储引擎)

-DWITH_BLACKHOLE_STORAGE_ENGINE=1(使用blackhole黑洞存储引擎)

-DWITH_FEDERATED_STORAGE_ENGINE=1(使用federated联合存储引擎)

若要明确指定不编译某存储引擎,可以使用类似如下的选项:

-DWITHOUT_<ENGINE>_STORAGE_ENGINE=1

比如:

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1

-DWITHOUT_FEDERATED_STORAGE_ENGINE=1

-DWITHOUT_PARTITION_STORAGE_ENGINE=1

如若要编译进其它功能,如SSL等,则可使用类似如下选项来实现编译时使用某库或不使用某库:

-DWITH_READLINE=1(可以批量导入mysql数据)

-DWITH_SSL=system(支持ssl会话)

-DWITH_ZLIB=system(ZLIB压缩库)

-DWITH_LIBWRAP=0(编译mysql是不是针对tcpwrap进行编译,使用tcpwrap实现访问控制)

其它常用的选项:

-DMYSQL_TCP_PORT=3306(默认短裤)

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock(默认套接字文件路径)

-DENABLED_LOCAL_INFILE=1(是否启用local_infile)

-DEXTRA_CHARSETS=all(是否支持其它额外的字符集)

-DDEFAULT_CHARSET=utf8(默认字符)

-DDEFAULT_COLLATION=utf8_general_ci(默认排序规则)

-DWITH_DEBUG=0(不启用debug功能)

-DENABLE_PROFILING=1(启用性能分析)

如果想清理此前的编译所生成的文件,则需要使用如下命令:

make clean

rm CMakeCache.txt

2、编译安装

# groupadd -r mysql

# useradd -g mysql -r -d /data/mydata mysql

# tar xf mysql-5.5.25a.tar.gz

# cd mysql-5.5.25a

# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \(默认安装路径)

    -DMYSQL_DATADIR=/mydata/data \(数据路径)

    -DSYSCONFDIR=/etc \(配置文件路径)

  -DWITH_INNOBASE_STORAGE_ENGINE=1 \(是否包含innobase存储引擎)

    -DWITH_ARCHIVE_STORAGE_ENGINE=1 \(是否包含archive存储引擎)

    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \(是否包含黑洞存储引擎)

  -DWITH_READLINE=1 \

  -DWITH_SSL=system \

  -DWITH_ZLIB=system \

  -DWITH_LIBWRAP=0 \

  -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \(unix套接字路径)

  -DDEFAULT_CHARSET=utf8 \(默认字符集)

    -DDEFAULT_COLLATION=utf8_general_ci

# make

# make install

[root@localhost ~]# yum grouplist(查看yum源软件包组)
Loaded plugins: katello, product-id, security, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
Setting up Group Process
Error: No group data available for configured repositories
[root@localhost ~]# wget ftp://172.16.0.1/pub/gls/server.repo -O /etc/yum.repos.d/server.repo(通过互联网下载server.repo文件,-O更改保存目录)
[root@localhost ~]# yum grouplist(查看yum源软件包组)
Loaded plugins: katello, product-id, security, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
Setting up Group Process
Installed Groups:
   Administration Tools
   Editors
   GNOME Desktop Environment
   Games and Entertainment
   Graphical Internet
   Graphics
   Legacy Network Server
   Legacy Software Development
   Legacy Software Support
   Mail Server
   Network Servers
   Office/Productivity
   Printing Support
   Server Configuration Tools
   Sound and Video
   System Tools
   Text-based Internet
   X Window System
Available Groups:
   Authoring and Publishing
   Cluster Storage
   Clustering
   DNS Name Server
   Development Libraries
   Development Tools
   Engineering and Scientific
   FTP Server
   GNOME Software Development
   Java Development
   KDE (K Desktop Environment)
   KDE Software Development
   MySQL Database
   News Server
   OpenFabrics Enterprise Distribution
   PostgreSQL Database
   Web Server
   Windows File Server
   X Software Development
   Xen
Done
[root@localhost ~]# yum -y groupinstall "Development Libraries" "Development Tools"(通过yum源安装开发库和开发组建)
[root@localhost ~]# lftp 172.16.0.1/pub/Sources(连接ftp服务器)
cd ok, cwd=/pub/Sources
lftp 172.16.0.1:/pub/Sources> cd mysql-5.5(切换到mysql-5.5目录)
lftp 172.16.0.1:/pub/Sources/mysql-5.5> get cmake-2.8.8.tar.gz(下载cmake-2.8.8)
5691656 bytes transferred
lftp 172.16.0.1:/pub/Sources/mysql-5.5> get mysql-5.5.28.tar.gz(下载mysql-5.5.28)
24739429 bytes transferred in 2 seconds (12.09M/s)
lftp 172.16.0.1:/pub/Sources/mysql-5.5> bye(退出)
[root@localhost ~]# ls(查看当前目录文件及子目录)
anaconda-ks.cfg  cmake-2.8.8.tar.gz  install.log  install.log.syslog  mysql-5.5.28.tar.gz
[root@localhost ~]# tar xf cmake-2.8.8.tar.gz(解压cmake文件,x解压,f后面跟文件明) 
[root@localhost ~]# hwclock -s(将硬件时间同步到系统时间)
[root@localhost ~]# hwclock(查看硬件时间)
Tue 23 Feb 2016 09:55:33 PM CST  -0.017300 seconds
[root@localhost ~]# tar xf mysql-5.5.28.tar.gz(解压mysql-5.5.28文件,x解压,f后面跟文件名)
[root@localhost ~]# cd cmake-2.8.8(切换到cmake-2.8.8目录)
[root@localhost cmake-2.8.8]# ls(查看当前目录文件及子目录)
bootstrap         CMakeCPackOptions.cmake.in  cmake_uninstall.cmake.in  CTestConfig.cmake     DartLocal.conf.in  Modules     Tests
ChangeLog.manual  CMakeGraphVizOptions.cmake  CompileFlags.cmake        CTestCustom.cmake.in  Docs               Readme.txt  Utilities
ChangeLog.txt     CMakeLists.txt              configure                 CTestCustom.ctest.in  doxygen.config     Source
CMakeCPack.cmake  CMakeLogo.gif               Copyright.txt             DartConfig.cmake      Example            Templates
[root@localhost cmake-2.8.8]# ./configure --help | less(查看cmake配置帮助并分页显示)
[root@localhost cmake-2.8.8]# ./configure(配置cmake)
[root@localhost cmake-2.8.8]# make && make install(编译并安装)
[root@localhost ~]# fdisk /dev/sda(管理磁盘分区,进入交互式)

The number of cylinders for this disk is set to 6527.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n(创建新的分区)
Command action
   e   extended
   p   primary partition (1-4)
e(扩展分区)
Selected partition 4
First cylinder (2756-6527, default 2756):  
Using default value 2756
Last cylinder or +size or +sizeM or +sizeK (2756-6527, default 6527): 
Using default value 6527

Command (m for help): n(创建新分区)
First cylinder (2756-6527, default 2756): 
Using default value 2756
Last cylinder or +size or +sizeM or +sizeK (2756-6527, default 6527): +20G(创建20G分区)

Command (m for help): t(更改分区类型)
Partition number (1-5): 5(更改第5个分区)
Hex code (type L to list codes): 8e(类型为lvm)
Changed system type of partition 5 to 8e (Linux LVM)

Command (m for help): p(查看分区情况)

Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2624    20972857+  83  Linux
/dev/sda3            2625        2755     1052257+  82  Linux swap / Solaris
/dev/sda4            2756        6527    30298590    5  Extended
/dev/sda5            2756        5188    19543041   8e  Linux LVM

Command (m for help): w(保存退出)
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@localhost ~]# partprobe /dev/sda(让内核重新加载sda分区表)
[root@localhost ~]# pvcreate /dev/sda5(将/dev/sda5创建为物理卷)
  Writing physical volume data to disk "/dev/sda5"
  Physical volume "/dev/sda5" successfully created
[root@localhost ~]# vgcreate myvg /dev/sda5(创建卷组myvg并将sda5加入到卷组) 
  Volume group "myvg" successfully created
[root@localhost ~]# lvcreate -L 10G -n mydata myvg(创建LV逻辑卷,-L大小为10G,-n名字为mydata,在myvg卷组中创建)        
  Logical volume "mydata" created
[root@localhost ~]# lvs(查看系统上LV逻辑卷信息)
  LV     VG   Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  mydata myvg -wi-a- 10.00G        
[root@localhost ~]# mke2fs -j /dev/myvg/mydata(将逻辑卷mydata格式化为ext3文件系统,-j带日志文件系统) 
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1310720 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost ~]# mkdir /mydata(创建/mydata目录)
[root@localhost ~]# vim /etc/fstab(编辑fstab文件)

LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=SWAP-sda3         swap                    swap    defaults        0 0
/dev/myvg/mydata        /mydata                 ext3    defaults        0 0

提示:将/dev/myvg/mydata逻辑卷开机自动挂在到/mydata目录,有人说mysql的数据放在xf文件系统性能是最好的,如果操作系统支持xf文件系统可以试试;
[root@localhost ~]# mount -a(挂在/etc/fstab文件中所有文件系统)
[root@localhost ~]# mkdir /mydata/data(创建data目录)
[root@localhost ~]# ls /mydata/(查看/mydata目录文件及子目录)
data  lost+found
[root@localhost ~]# groupadd -r mysql(创建系统组mysql)
[root@localhost ~]# useradd -r -g mysql -s /sbin/nologin mysql(创建系统用户mysql并加入到mysql组,-r系统用户,-g指定基本组,-s执行默认shell)
[root@localhost ~]# id mysql(查看mysql用户信息)       
uid=101(mysql) gid=156(mysql) groups=156(mysql) context=root:system_r:unconfined_t:SystemLow-SystemHigh
[root@localhost ~]# chown -R mysql.mysql /mydata/data/(更改/mydata/data的属主属组为mysql,-R递归更改)
[root@localhost ~]# which cmake(查找camke命令的绝对路径)
/usr/local/bin/cmake
[root@localhost ~]# echo $PATH(查看PATH命令路径环境变量)
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost mysql-5.5.28]# ccmake . 
                                                     Page 0 of 1
 EMPTY CACHE(空的缓存)










EMPTY CACHE: 
Press [enter] to edit option CMake Version 2.8.8
Press [c] to configure
Press [h] for help           Press [q] to quit without generating
Press [t] to toggle advanced mode (Currently Off)
[root@localhost mysql-5.5.28]# cmake . -LH (查看帮助,并可以读取选项尝试编译)

// Choose the type of build, options are: None(CMAKE_CXX_FLAGS or
 CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel
CMAKE_BUILD_TYPE:STRING=RelWithDebInfo

// install prefix
CMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql(默认安装路径)

// Set to true if this is a community build
COMMUNITY_BUILD:BOOL=ON

// Enable profiling
ENABLED_PROFILING:BOOL=ON(启用分析)

// Enable debug sync (debug builds only)
ENABLE_DEBUG_SYNC:BOOL=ON(启用debug)

// Enable gcov (debug, Linux builds only)
ENABLE_GCOV:BOOL=OFF

// Installation directory layout. Options are: STANDALONE (as in zip or tar.gz installer), RPM, DEB, SVR4
INSTALL_LAYOUT:STRING=STANDALONE

// default MySQL data directory
MYSQL_DATADIR:PATH=/usr/local/mysql/data(数据文件目录)

// MySQL maintainer-specific development environment
MYSQL_MAINTAINER_MODE:BOOL=OFF

// Link ARCHIVE statically to the server
WITH_ARCHIVE_STORAGE_ENGINE:BOOL=OFF

// Link BLACKHOLE statically to the server
WITH_BLACKHOLE_STORAGE_ENGINE:BOOL=OFF

// Use dbug/safemutex
WITH_DEBUG:BOOL=OFF

// Compile MySQL with embedded server
WITH_EMBEDDED_SERVER:BOOL=OFF

// Options are: none, complex, all
WITH_EXTRA_CHARSETS:STRING=all(是否支持其它额外的字符集)

// Link FEDERATED statically to the server
WITH_FEDERATED_STORAGE_ENGINE:BOOL=OFF

// Link INNOBASE statically to the server
WITH_INNOBASE_STORAGE_ENGINE:BOOL=ON

// Use bundled libedit
WITH_LIBEDIT:BOOL=ON

// Compile with tcp wrappers support
WITH_LIBWRAP:BOOL=OFF

// Link PARTITION statically to the server
WITH_PARTITION_STORAGE_ENGINE:BOOL=ON

// Link PERFSCHEMA statically to the server
WITH_PERFSCHEMA_STORAGE_ENGINE:BOOL=ON

// Generate PIC objects
WITH_PIC:BOOL=OFF

// Use bundled readline
WITH_READLINE:BOOL=OFF

// Options are : no, bundled, yes (prefer os library if present otherwise use bundled), system (use os library)
WITH_SSL:STRING=no

// Compile MySQL with unit tests
WITH_UNIT_TESTS:BOOL=ON

// Valgrind instrumentation
WITH_VALGRIND:BOOL=OFF

// Which zlib to use (possible values are 'bundled' or 'system')
WITH_ZLIB:STRING=system

[root@localhost mysql-5.5.28]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data -DSYSCONFDIR=/etc -DWITH_I
NNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_
ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock(配置mysql)     
-- MySQL 5.5.28
-- Packaging as: mysql-5.5.28-Linux-i686
-- Found OpenSSL: /usr/lib/libssl.so;/usr/lib/libcrypto.so (found version "0.9.8e-rhel5") 
-- Looking for SHA512_DIGEST_LENGTH
-- Looking for SHA512_DIGEST_LENGTH - found
-- Configuring done
-- Generating done
-- Build files have been written to: /root/mysql-5.5.28
[root@localhost mysql-5.5.28]# make(编译) 
[root@localhost mysql-5.5.28]# make install(安装)
[root@localhost mysql-5.5.28]# cd /usr/local/mysql/(切换到/usr/local/mysql目录)
[root@localhost mysql]# ls(查看当前目录文件及子目录)
bin  COPYING  data  docs  include  INSTALL-BINARY  lib  man  mysql-test  README  scripts  share  sql-bench  support-files
[root@localhost mysql]# ll(查看当前目录文件及子目录详细信息)
total 132
drwxr-xr-x  2 root root  4096 Feb 24 00:19 bin
-rw-r--r--  1 root root 17987 Aug 29  2012 COPYING
drwxr-xr-x  4 root root  4096 Feb 24 00:18 data
drwxr-xr-x  2 root root  4096 Feb 24 00:18 docs
drwxr-xr-x  3 root root  4096 Feb 24 00:18 include
-rw-r--r--  1 root root  7604 Aug 29  2012 INSTALL-BINARY
drwxr-xr-x  3 root root  4096 Feb 24 00:18 lib
drwxr-xr-x  4 root root  4096 Feb 24 00:19 man
drwxr-xr-x 10 root root  4096 Feb 24 00:19 mysql-test
-rw-r--r--  1 root root  2552 Aug 29  2012 README
drwxr-xr-x  2 root root  4096 Feb 24 00:19 scripts
drwxr-xr-x 27 root root  4096 Feb 24 00:19 share
drwxr-xr-x  4 root root  4096 Feb 24 00:19 sql-bench
drwxr-xr-x  2 root root  4096 Feb 24 00:19 support-files
[root@localhost mysql]# chown -R :mysql /usr/local/mysql/(更改/usr/local/mysql目录文件及子目录的属组为mysql,-R递归更改)
[root@localhost mysql]# ll
total 132
drwxr-xr-x  2 root mysql  4096 Feb 24 00:19 bin
-rw-r--r--  1 root mysql 17987 Aug 29  2012 COPYING
drwxr-xr-x  4 root mysql  4096 Feb 24 00:18 data
drwxr-xr-x  2 root mysql  4096 Feb 24 00:18 docs
drwxr-xr-x  3 root mysql  4096 Feb 24 00:18 include
-rw-r--r--  1 root mysql  7604 Aug 29  2012 INSTALL-BINARY
drwxr-xr-x  3 root mysql  4096 Feb 24 00:18 lib
drwxr-xr-x  4 root mysql  4096 Feb 24 00:19 man
drwxr-xr-x 10 root mysql  4096 Feb 24 00:19 mysql-test
-rw-r--r--  1 root mysql  2552 Aug 29  2012 README
drwxr-xr-x  2 root mysql  4096 Feb 24 00:19 scripts
drwxr-xr-x 27 root mysql  4096 Feb 24 00:19 share
drwxr-xr-x  4 root mysql  4096 Feb 24 00:19 sql-bench
drwxr-xr-x  2 root mysql  4096 Feb 24 00:19 support-files
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data(初始化mysql,--user指定运行mysql用户,--datadir指定mysql
数据文件目录)
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl

Please report any problems with the ./bin/mysqlbug script!
[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf(复制mysql配置文件)
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld(复制mysql服务脚本)
[root@localhost mysql]# chkconfig --add mysqld(将mysqld添加到服务列表)
[root@localhost mysql]# chkconfig --list mysqld(查看mysqld服务在相应系统级别启动情况)
mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@localhost mysql]# service mysqld start(启动mysqld服务)
Starting MySQL...                                          [  OK  ]
[root@localhost mysql]# vim /etc/profile.d/mysql.sh(将mysql客户端命令添加到环境变量)

export PATH=$PATH:/usr/local/mysql/bin

[root@localhost mysql]# . /etc/profile.d/mysql.sh(执行mysql.sh脚本,让环境变量生效)
[root@localhost mysql]# echo $PATH(显示PATH环境变量的值)
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
[root@localhost mysql]# mysql(连接mysql服务器)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.28-log Source distribution(版本为5.5.28源码版本)

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;(查看数据库)
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> show engines;(查看mysql存储引擎)
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
8 rows in set (0.01 sec)

提示:InoDB是默认存储引擎;

mysql> \q(退出mysql)
Bye
[root@localhost mysql]# vim /etc/my.cnf(编辑mysql配置文件)

datadir = /mydata/data

thread_concurrency = 8(线程数)

提示:为了保证mysql以后的运行是正常的,确保datadir = /mydata/data,由于编译的时候已经指向/mydata/data,所以这里就算没改也不会出错,但要使用通用二进制格式不
改启动就出错;
[root@localhost mysql]# cd(切换到用户家目录)
[root@localhost ~]# mysql(连接mysql)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> DROP USER ''@localhost;(删除匿名用户)
Query OK, 0 rows affected (0.00 sec)

mysql> DROP USER ''@'127.0.0.1';(删除匿名用户)
ERROR 1396 (HY000): Operation DROP USER failed for ''@'127.0.0.1'

提示:没有这个用户;

mysql> \q(退出mysql)
Bye

[root@localhost ~]# mysql(连接mysql数据库)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> USE mysql(打开mysql数据库)
Database changed

mysql> SELECT User,Host,Password FROM user;(找出user表User,Host,Password字段数据)
+------+-----------------------+----------+
| User | Host                  | Password |
+------+-----------------------+----------+
| root | localhost             |          |
| root | localhost.localdomain |          |
| root | 127.0.0.1             |          |
| root | ::1                   |          |
|      | localhost.localdomain |          |
+------+-----------------------+----------+
5 rows in set (0.00 sec)

mysql> DROP USER ''@'localhost.localdomain';(删除匿名用户)
Query OK, 0 rows affected (0.00 sec)

mysql> DROP USER 'root'@'::1';(删除监听在ipv6地址上的用户)
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT User,Host,Password FROM user;(找出user表User, Host, Password字段数据)
+------+-----------------------+----------+
| User | Host                  | Password |
+------+-----------------------+----------+
| root | localhost             |          |
| root | localhost.localdomain |          |
| root | 127.0.0.1             |          |
+------+-----------------------+----------+
3 rows in set (0.00 sec)

mysql> UPDATE user SET Password=PASSWORD('redhat') WHERE user='root';(更新user表设置Password字段函数为redhat,条件user字段为root)
Query OK, 3 rows affected (0.03 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> SELECT User,Host,Password FROM user;(找出user表User,Host,Password字段内容)
+------+-----------------------+-------------------------------------------+
| User | Host                  | Password                                  |
+------+-----------------------+-------------------------------------------+
| root | localhost             | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| root | localhost.localdomain | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| root | 127.0.0.1             | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
+------+-----------------------+-------------------------------------------+
3 rows in set (0.00 sec)

mysql> FLUSH PRIVILEGES;(刷新权限表)
Query OK, 0 rows affected (0.00 sec)

mysql> \q(退出)
Bye

[root@localhost ~]# mysql(连接mysql服务)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
提示:无法连接;
[root@localhost ~]# mysql -uroot -h172.16.100.1 -p(连接mysql,-u指定用户,-h指定主机,-p指定密码)
Enter password: 
ERROR 1130 (HY000): Host '172.16.100.1' is not allowed to connect to this MySQL server
提示:连接不上去,因为此时这三个用户只允许本机连接;
[root@localhost ~]# mysql -uroot -p(连接mysql数据库,-u指定用户,-p指定密码)
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

提示:mysql的用户即包含了用户名还包含了允许所使用的客户端主机;

mysql> \q(退出Mysql)
Bye

[root@localhost ~]# mysql(连接mysql数据库)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost ~]# vim .my.cnf

[client]
username=root
password=redhat
hostname=localhost

提示:后想通过本机连接,即不想使用-u指定用户名,也不想指定密码,在自己家目录下创建.my.cnf隐藏文件,当然不能让别人访问;
[root@localhost ~]# mysql(连接Mysql数据库)
mysql: unknown variable 'username=root'
[root@localhost ~]# vim .my.cnf(编辑.my.cnf文件)

[client]
username='root'
password='redhat'
hostname='localhost'

[root@localhost ~]# mysql(连接mysql数据库)
mysql: unknown variable 'username=root'
[root@localhost ~]# vim /etc/my.cnf(编辑mysql配置文件)
[root@localhost ~]# vim .my.cnf(编辑.my.cnf文件)

[client]
user = 'root'
password = 'redhat'
host = 'localhost'

[root@localhost ~]# mysql(连接mysql数据库)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \q(退出)
Bye

提示:它会自己读取~/.my.cnf配置文件获取它的配置信息;
[root@localhost ~]# vim .my.cnf(编辑.my.cnf文件)

[client]
user = 'root'
password = 'redhat'
host = 'localhost'

[root@localhost ~]# mysql(连接mysql)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \q(退出)
Bye

[root@localhost ~]# cd /usr/local/mysql/(切换到/usr/local/mysql目录)
[root@localhost mysql]# cd /mydata/data/(切换到mysql数据目录)
[root@localhost data]# ls(查看当前目录文件及子目录)
ibdata1  ib_logfile0  ib_logfile1  localhost.localdomain.err  localhost.localdomain.pid  mysql  mysql-bin.000001  mysql-bin.index  
performance_schema  test
提示:每个数据库都有一个目录;
[root@localhost mysql]# ls(查看当前目录文件及子目录)
columns_priv.frm  func.frm           help_keyword.frm   host.frm              proc.frm          servers.frm      time_zone.frm
time_zone_transition.frm             columns_priv.MYD   func.MYD              help_keyword.MYD  host.MYD         proc.MYD
servers.MYD       time_zone_leap_second.frm             time_zone_transition.MYD                columns_priv.MYI func.MYI
help_keyword.MYI  host.MYI           proc.MYI           servers.MYI           time_zone_leap_second.MYD          time_zone_transition.MYI
db.frm            general_log.CSM    help_relation.frm  ndb_binlog_index.frm  procs_priv.frm    slow_log.CSM     time_zone_leap_second.MYI
time_zone_transition_type.frm        db.MYD             general_log.CSV       help_relation.MYD ndb_binlog_index.MYD  
procs_priv.MYD    slow_log.CSV       time_zone.MYD      time_zone_transition_type.MYD           db.MYI           general_log.frm
help_relation.MYI ndb_binlog_index.MYI                  procs_priv.MYI        slow_log.frm      time_zone.MYI    time_zone_transition_type.MYI
event.frm         help_category.frm  help_topic.frm     plugin.frm            proxies_priv.frm  tables_priv.frm  time_zone_name.frm
user.frm          event.MYD          help_category.MYD  help_topic.MYD        plugin.MYD        proxies_priv.MYD tables_priv.MYD  
time_zone_name.MYD                   user.MYD           event.MYI             help_category.MYI help_topic.MYI   plugin.MYI
proxies_priv.MYI  tables_priv.MYI    time_zone_name.MYI user.MYI
提示:这里面有许多表,每个表有三个文件,.frm是表结构定义,.MYD数据文件,.MYI是索引文件,索引文件是独立的文件对于mysql而言;
[root@localhost mysql]# mysql(连接mysql数据库)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW VARIABLES LIKE '%innodb%';(查看跟innodb相关的所有选项,变量,可以使用GLOBAL查看全局变量,不使用查看会话变量)
+---------------------------------+------------------------+
| Variable_name                   | Value                  |
+---------------------------------+------------------------+
| have_innodb                     | YES                    |
| ignore_builtin_innodb           | OFF                    |
| innodb_adaptive_flushing        | ON                     |
| innodb_adaptive_hash_index      | ON                     |
| innodb_additional_mem_pool_size | 8388608                |
| innodb_autoextend_increment     | 8                      |
| innodb_autoinc_lock_mode        | 1                      |
| innodb_buffer_pool_instances    | 1                      |
| innodb_buffer_pool_size         | 134217728              |
| innodb_change_buffering         | all                    |
| innodb_checksums                | ON                     |
| innodb_commit_concurrency       | 0                      |
| innodb_concurrency_tickets      | 500                    |
| innodb_data_file_path           | ibdata1:10M:autoextend |
| innodb_data_home_dir            |                        |
| innodb_doublewrite              | ON                     |
| innodb_fast_shutdown            | 1                      |
| innodb_file_format              | Antelope               |
| innodb_file_format_check        | ON                     |
| innodb_file_format_max          | Antelope               |
| innodb_file_per_table           | OFF                    |(是不是每张表使用独立的文件,如果想使用,将Innodb_file_per_table复制出来改成ON,但是是
临时有效,不会永久有效)
| innodb_flush_log_at_trx_commit  | 1                      |
| innodb_flush_method             |                        |
| innodb_force_load_corrupted     | OFF                    |
| innodb_force_recovery           | 0                      |
| innodb_io_capacity              | 200                    |
| innodb_large_prefix             | OFF                    |
| innodb_lock_wait_timeout        | 50                     |
| innodb_locks_unsafe_for_binlog  | OFF                    |
| innodb_log_buffer_size          | 8388608                |
| innodb_log_file_size            | 5242880                |
| innodb_log_files_in_group       | 2                      |
| innodb_log_group_home_dir       | ./                     |
| innodb_max_dirty_pages_pct      | 75                     |
| innodb_max_purge_lag            | 0                      |
| innodb_mirrored_log_groups      | 1                      |
| innodb_old_blocks_pct           | 37                     |
| innodb_old_blocks_time          | 0                      |
| innodb_open_files               | 300                    |
| innodb_purge_batch_size         | 20                     |
| innodb_purge_threads            | 0                      |
| innodb_random_read_ahead        | OFF                    |
| innodb_read_ahead_threshold     | 56                     |
| innodb_read_io_threads          | 4                      |
| innodb_replication_delay        | 0                      |
| innodb_rollback_on_timeout      | OFF                    |
| innodb_rollback_segments        | 128                    |
| innodb_spin_wait_delay          | 6                      |
| innodb_stats_method             | nulls_equal            |
| innodb_stats_on_metadata        | ON                     |
| innodb_stats_sample_pages       | 8                      |
| innodb_strict_mode              | OFF                    |
| innodb_support_xa               | ON                     |
| innodb_sync_spin_loops          | 30                     |
| innodb_table_locks              | ON                     |
| innodb_thread_concurrency       | 0                      |
| innodb_thread_sleep_delay       | 10000                  |
| innodb_use_native_aio           | OFF                    |
| innodb_use_sys_malloc           | ON                     |
| innodb_version                  | 1.1.8                  |
| innodb_write_io_threads         | 4                      |
+---------------------------------+------------------------+
61 rows in set (0.04 sec)

mysql> \q(退出mysql)
Bye

[root@localhost mysql]# vim /etc/my.cnf(编辑mysql配置文件)

[mysqld]

innodb_file_per_table = 1

提示:要想innodb_file_per_table改为ON永久有效编辑/etc/my.cnf配置文件,找到[mysqld]项添加innodb_file_per_table = 1;

[root@localhost mysql]# service mysqld restart(重启mysqld服务)
Shutting down MySQL.                                       [  OK  ]
Starting MySQL..                                           [  OK  ]
[root@localhost mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW GLOBAL VARIABLES LIKE '%innodb%';(查看跟innodb相关的所有选项,变量,GLOBAL查看全局变量,不使用查看会话变量)
+---------------------------------+------------------------+
| Variable_name                   | Value                  |
+---------------------------------+------------------------+
| have_innodb                     | YES                    |
| ignore_builtin_innodb           | OFF                    |
| innodb_adaptive_flushing        | ON                     |
| innodb_adaptive_hash_index      | ON                     |
| innodb_additional_mem_pool_size | 8388608                |
| innodb_autoextend_increment     | 8                      |
| innodb_autoinc_lock_mode        | 1                      |
| innodb_buffer_pool_instances    | 1                      |
| innodb_buffer_pool_size         | 134217728              |
| innodb_change_buffering         | all                    |
| innodb_checksums                | ON                     |
| innodb_commit_concurrency       | 0                      |
| innodb_concurrency_tickets      | 500                    |
| innodb_data_file_path           | ibdata1:10M:autoextend |
| innodb_data_home_dir            |                        |
| innodb_doublewrite              | ON                     |
| innodb_fast_shutdown            | 1                      |
| innodb_file_format              | Antelope               |
| innodb_file_format_check        | ON                     |
| innodb_file_format_max          | Antelope               |
| innodb_file_per_table           | ON                     |
| innodb_flush_log_at_trx_commit  | 1                      |
| innodb_flush_method             |                        |
| innodb_force_load_corrupted     | OFF                    |
| innodb_force_recovery           | 0                      |
| innodb_io_capacity              | 200                    |
| innodb_large_prefix             | OFF                    |
| innodb_lock_wait_timeout        | 50                     |
| innodb_locks_unsafe_for_binlog  | OFF                    |
| innodb_log_buffer_size          | 8388608                |
| innodb_log_file_size            | 5242880                |
| innodb_log_files_in_group       | 2                      |
| innodb_log_group_home_dir       | ./                     |
| innodb_max_dirty_pages_pct      | 75                     |
| innodb_max_purge_lag            | 0                      |
| innodb_mirrored_log_groups      | 1                      |
| innodb_old_blocks_pct           | 37                     |
| innodb_old_blocks_time          | 0                      |
| innodb_open_files               | 300                    |
| innodb_purge_batch_size         | 20                     |
| innodb_purge_threads            | 0                      |
| innodb_random_read_ahead        | OFF                    |
| innodb_read_ahead_threshold     | 56                     |
| innodb_read_io_threads          | 4                      |
| innodb_replication_delay        | 0                      |
| innodb_rollback_on_timeout      | OFF                    |
| innodb_rollback_segments        | 128                    |
| innodb_spin_wait_delay          | 6                      |
| innodb_stats_method             | nulls_equal            |
| innodb_stats_on_metadata        | ON                     |
| innodb_stats_sample_pages       | 8                      |
| innodb_strict_mode              | OFF                    |
| innodb_support_xa               | ON                     |
| innodb_sync_spin_loops          | 30                     |
| innodb_table_locks              | ON                     |
| innodb_thread_concurrency       | 0                      |
| innodb_thread_sleep_delay       | 10000                  |
| innodb_use_native_aio           | OFF                    |
| innodb_use_sys_malloc           | ON                     |
| innodb_version                  | 1.1.8                  |
| innodb_write_io_threads         | 4                      |
+---------------------------------+------------------------+
61 rows in set (0.01 sec)

提示:innodb_file_per_table已经ON状态;

mysql> CREATE DATABASE mydb;(创建数据库叫mydb)
Query OK, 1 row affected (0.01 sec)

mysql> USE mydb;(进入mydb数据库)
Database changed

mysql> CREATE TABLE testdb( id INT NOT NULL, name CHAR(30));(创建表testdb,id字段整形不允许为空,name字段字符型30字节)
Query OK, 0 rows affected (0.05 sec)

mysql> \q(退出)
Bye

[root@localhost mysql]# pwd(查看当前所处的路径)
/mydata/data/mysql
[root@localhost mysql]# cd ..(切换到上级目录)
[root@localhost data]# ls(查看当前目录文件及子目录)
ibdata1  ib_logfile0  ib_logfile1  localhost.localdomain.err  localhost.localdomain.pid  mydb  mysql  mysql-bin.000001  mysql-bin.000002  
mysql-bin.index  performance_schema  test
[root@localhost data]# cd mydb/(切换到mydb目录)
[root@localhost mydb]# ls(查看当前目录文件及子目录)
db.opt  testdb.frm(表结构)  testdb.ibd(表空间,同时存储表数据和表索引)
[root@localhost mydb]# ls -lh(查看当前目录文件及子目录详细信息并做单位换算)
total 128K
-rw-rw---- 1 mysql mysql   65 Feb 24 11:56 db.opt
-rw-rw---- 1 mysql mysql 8.4K Feb 24 11:58 testdb.frm
-rw-rw---- 1 mysql mysql  96K Feb 24 11:58 testdb.ibd
提示:ibd文件里面根本没存储任何数据,它还有初始数据;
[root@localhost mydb]# ls ../mysql(查看mysql目录文件及子目录)
columns_priv.frm  help_category.frm  ndb_binlog_index.frm  servers.frm                time_zone_name.frm
columns_priv.MYD  help_category.MYD  ndb_binlog_index.MYD  servers.MYD                time_zone_name.MYD
columns_priv.MYI  help_category.MYI  ndb_binlog_index.MYI  servers.MYI                time_zone_name.MYI
db.frm            help_keyword.frm   plugin.frm            slow_log.CSM               time_zone_transition.frm
db.MYD            help_keyword.MYD   plugin.MYD            slow_log.CSV               time_zone_transition.MYD
db.MYI            help_keyword.MYI   plugin.MYI            slow_log.frm               time_zone_transition.MYI
event.frm         help_relation.frm  proc.frm              tables_priv.frm            time_zone_transition_type.frm
event.MYD         help_relation.MYD  proc.MYD              tables_priv.MYD            time_zone_transition_type.MYD
event.MYI         help_relation.MYI  proc.MYI              tables_priv.MYI            time_zone_transition_type.MYI
func.frm          help_topic.frm     procs_priv.frm        time_zone.frm              user.frm
func.MYD          help_topic.MYD     procs_priv.MYD        time_zone_leap_second.frm  user.MYD
func.MYI          help_topic.MYI     procs_priv.MYI        time_zone_leap_second.MYD  user.MYI
general_log.CSM   host.frm           proxies_priv.frm      time_zone_leap_second.MYI
general_log.CSV   host.MYD           proxies_priv.MYD      time_zone.MYD
general_log.frm   host.MYI           proxies_priv.MYI      time_zone.MYI
[root@localhost mydb]# ls(查看当前目录文件及子目录)
db.opt  testdb.frm  testdb.ibd
[root@localhost mydb]# file db.opt(查看db.opt文件类型)
db.opt: ASCII text(文本文件类型)
[root@localhost mydb]# cat db.opt(查看db.opt文件内容)
default-character-set=latin1
default-collation=latin1_swedish_ci
提示:.opt是当前数据库默认字符集和排序规则的定义,数据库的选项;
[root@localhost mydb]# cd(切换到用户家目录)
[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \?(查看mysql客户端支持的命令)

For information about MySQL products and services, visit:
   http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
   http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
   https://shop.mysql.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

For server side help, type 'help contents'

mysql> \q(退出)
Bye

mysql>

mysql

  --user, -u: 用户

  --host, -h: 主机

  --password, -p: 密码

  --port: 端口

  --protocol: 协议

  --database DATABASE, -D:连入数据库以后直接将某个数据库设定为默认库;

其它选项:

mysql>

  交互式模式

  批处理模式(脚本模式)

    mysql < init.sql(init.sql语句直接被载入mysql,并执行)

mysql>

  命令两类:

    客户端命令

    服务器语句: 有语句结束符,默认;分号;

      \d: 定义语句结束符

  客户端命令:

    \c: 提前终止语句结束

    \g: 无论语句结束符是什么,直接将此语句送至服务器端执行;

    \G: 无论语句结束符是什么,直接将此语句送到服务器端执行,而且结果以竖排方式显示;

    \!: COMMAND: 执行shell命令;

    \W: 语句执行结束后显示警告信息;

    \w: 语句执行结束后不显示警告信息;

    \#: 对新建的对象,支持补全功能;

mysql>

/* d(多行注释信息,中间内容都是注释,是不会被执行的)

  fds

*/

mysql>

  ->: 可以输入新语句

  '>: 缺少单引号后一半

  ">: 缺少双引号后一半

  `>: 缺少反引号后一半

补全:

  名次补全: 数据库名称、字段名称补全都能实现,但是每一个名称补全的功能都有前提打开数据库的时候必须要将某一个数据库的名称和每一个库中的每个表的名称每个表每个字段的名称都要载入内存里面才能补全的,这可能会导致再连接mysql数据库的时候有大量的时间延迟,因为它必须要遍历每一个数据库的每一个表的定义;

服务器端命令获取帮助:

  help KEYWORD: 获取服务器端命令帮助;

# mysqladmin [options] command [arg] [command [arg]] ...

# mysqladmin -uroot -p password 'NEW_PASS'(是root用户设定新密码)

  mysqladmin create DATABASE 创建数据库

  mysqladmin drop DATABASE 删除数据库

  mysqladmin ping 测试mysql数据库是否在线

  mysqladmin processlist 删除进程列表,列出服务器上正在执行的mysql线程;

  mysqladmin status 显示mysql状态

    --sleep N 每隔多长时间显示一次

    --count N 最多显示多少次;

  mysqladmin extended-status 显示扩展状态,显示状态变量及值,状态变量用来统计服务器工作当中的数据;

  mysqladmin variables: 显示服务器变量,定义服务器工作属性;

  mysqladmin flush-privileges: 刷新授权表,让mysqld重读授权表,等同于reload;

  mysqladmin flush-status: 重置大多数服务器状态变量;

  mysqladmin flush-logs: 二进制和中继日志滚动

  mysqladmin flush-hosts: 重置因为多次错误连接mysql而且禁用的用户主机;

  mysqladmin refresh: 相当于同时执行flush-hosts和flush-logs;

  mysqladmin shutdown: 关闭mysql服务器进程;

  mysqladmin version: 显示mysql的版本号及状态信息;

  mysqladmin start-slave: 启动复制,启动从服务器复制线程;

    SQL thread

    IO thread

  mysqladmin stop-slave: 关闭复制;

mysqldump(备份工具), mysqlimport(导入工具), mysqlcheck

开发视角:

  数据类型

  约束

  数据库、表、索引、视图

  SELECT

The mysql Prompts(mysql提示符)

Prompt Meaning of Prompt

  mysql> Ready for new statement(可以输入新语句)

    -> Waiting for next line of statement(语句没有结束还可以继续输入)

    '> Waiting for end of single-quoted string(只给'单引号,还缺少一部分)

    "> Waiting for end of double-quoted string or identifier(却双引号后一半)

    `> Waiting for end of backtick-quoted identifier(缺分引号后一半)

    /*> Waiting for end of C-style comment(缺多行注释的后一半)

Other common Options for Command-Line Tools

--compress: 语句先压缩再发送,可以节约带宽

--default-character-set=charset_name

--version or -V: 版本

--verbose or -v: 详细信息

--ssl-ca=/path/to/ssl_ca_file: 使用ssl指定ca证书文件;

--ssl-capath=/path/to/ca_dir: 使用ssl指定多个ca证书文件;

--ssl-cert=/path/to/cert_file: 自己的证书

--ssl-cipher=cipher_list: 加密算法列表

--ssl-key=/path/to/key_file: 密钥文件

--ssl-verify-server-cert: 是否验证服务器端证书

On non-Windows machines,mysql saves commands in a history file

  ~/.mysql_history

On non-Widnows machines,mysql has a tab completion feature

mysql> use cactidb;

Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -K(mysql的客户端也支持命令补全)

Database change

  To disable the feature,using one of the following options:(禁止补全功能选项)

    -A(禁止命令补全功能,连接mysql的时候使用-A选项)

    --no-auto-rehash(禁止名称补全功能)

    --disable-auto-rehash(禁止名称补全功能)

  To enable the feature for new objects,using one of the following commands;(对新建的对象启用这种功能使用的命令)

    \#

    rehash(启用名称补全功能)

mysql Output Formats(mysql的输出格式,默认以表格方式显示)

By default,mysql produces output in one of two formats,depending on whether you use it in interactive or batch mode

To select an output format different from either of the default formats, use these options:

  --html or -H(显示为html格式)

    Produce output in HTML format

  --xml or -X(显示为xml格式)

    Produce outpu in XML format

mysqladmin

Used to perform administrative tasks(管理专用命令)

  Some of the tasks include creating and dropping databases,displaying server configuration,current status information,changing a password,and stopping a

server.mysqladmin can be very useful in scripting situations

Systax:

mysqladmin [options] command [arg] [command [arg]] ...

mysqladmin Command Parameters(mysql命令参数)

create: 创建数据库

debug:

drop: 删除数据库

extended-status: 扩展的状态;

flush-hosts: 清除主机内部信息,重置因为多次错误连接mysql而禁用的用户主机;

flush-logs: 做日志滚动

flush-privileges: 刷新授权表

flush-status: 重置绝大多数的服务器状态变量;

flush-tables: 关闭所有打开的表文件句柄;

flush-threads: 重置线程缓存;

kill: 杀死一个线程;

password: 设置密码

ping: 测试对方数据库是否在线;

processlist: 进程列表,列出服务器上正在执行的mysql线程;

relead: 让mysqld重读授权表;

refresh: 关闭所有打开的表,并且滚动服务器日志;

shutdown: 关闭mysql服务器;

start-slave: 启动复制,启动从服务器复制线程;

status: 状态

stop-slave: 停止复制功能;

varlables: 服务器变量

version: 显示mysql服务器版本号以及状态相关的信息;

mysqladmin status

Used to return some basic information from mysqld including uptime,current number of threads, and queries per second being executed

  Can combine the status command with the --sleep option to have mysqladmin pause for the specified number of seconds and then display updated status information.(可以使用--sleep表示睡眠几秒钟)

  Unless you specifv the --count option(--count显示多少次)

[root@localhost mydb]# mysql(连接mysql数据库)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SELECT DATABASE();(查看当前默认数据库)
+------------+
| DATABASE() |
+------------+
| NULL       |
+------------+
1 row in set (0.00 sec)

mysql> USE mydb;(更改默认数据库为mydb)
Database changed

mysql> SELECT DATABASE();(查看当前默认数据库)
+------------+
| DATABASE() |
+------------+
| mydb       |
+------------+
1 row in set (0.00 sec)

mysql> \q(退出)
Bye

[root@localhost mydb]# mysql -D mydb(连接mysql数据库,-D指定默认数据库为mydb)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SELECT DATABASE();(查看默认数据库)
+------------+
| DATABASE() |
+------------+
| mydb       |
+------------+
1 row in set (0.00 sec)

提示:默认数据库已经是mydb;

mysql> \q(退出mysql)
Bye

[root@localhost mydb]# cd(切换到用户家目录)
[root@localhost ~]# vim test.sql(编辑test.sql文件)

CREATE DATABASE testdb;(创建数据库testdb)
CREATE TABLE testdb.tb1(id INT, name CHAR(20));(在testdb中创建表tb1,tb1表中有两个字段,id字段整形,name字段字符型并且20个字节)
[root@localhost ~]# mysql(连接mysql数据库)    
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \?(查看mysql客户端交互式命令)     

For information about MySQL products and services, visit:
   http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
   http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
   https://shop.mysql.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.(载入文件系统某个脚步)
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

For server side help, type 'help contents'

mysql> \. /root/test.sql(翟如test.sql脚本)
Query OK, 1 row affected (0.00 sec)

Query OK, 0 rows affected (0.58 sec)

mysql> SHOW DATABASES;(显示数据库)
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydb               |
| mysql              |
| performance_schema |
| test               |
| testdb             |
+--------------------+
6 rows in set (0.00 sec)

提示:testdb创建成功;

mysql> DROP DATABASE testdb;(删除testdb数据库)
Query OK, 1 row affected (0.19 sec)

mysql> SHOW DATABASES;(显示数据库)
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydb               |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

mysql> \q(退出mysql)
Bye

[root@localhost ~]# mysql < test.sql(使用输入重定向将test.sql脚步在mysql中执行)
[root@localhost ~]# mysql(连接mysql数据库)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW DATAbASES;(显示数据库)
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydb               |
| mysql              |
| performance_schema |
| test               |
| testdb             |
+--------------------+
6 rows in set (0.00 sec)

提示:数据库testdb创建好了;

mysql> USE testdb;(修改默认数据库为testdb)
Database changed

mysql> SHOW TABLES;(显示表)
+------------------+
| Tables_in_testdb |
+------------------+
| tb1              |
+------------------+
1 row in set (0.00 sec)

mysql> \q(退出mysql)
Bye

[root@localhost ~]# mysql(连接mysql数据库)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \?(查看mysql客户端命令)

For information about MySQL products and services, visit:
   http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
   http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
   https://shop.mysql.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.(用来定义mysql语句结束符,默认为;分号)
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

For server side help, type 'help contents'

mysql> delimiter //(使用//双斜线作为语句结束符)

mysql> SHOW DATAbASES(显示数据库)
    -> ;(分号不能结束)
    -> //(双斜线可以结束)
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydb               |
| mysql              |
| performance_schema |
| test               |
| testdb             |
+--------------------+
6 rows in set (0.01 sec)

mysql> SHOW DATABASES//(显示数据库)
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydb               |
| mysql              |
| performance_schema |
| test               |
| testdb             |
+--------------------+
6 rows in set (0.00 sec)

mysql> \d ;(使用;分号作为语句结束符)

mysql> SHOW DATABASES//(显示数据库,//双斜线无法结束语句)
    -> ;(;分号可以结束语句)
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the 
right syntax to use near '//' at line 1
mysql> SHOW DATABASES;(显示数据库)
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydb               |
| mysql              |
| performance_schema |
| test               |
| testdb             |
+--------------------+
6 rows in set (0.00 sec)

mysql> \?(查看mysql客户端命令)    

For information about MySQL products and services, visit:
   http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
   http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
   https://shop.mysql.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.(从服务器获取状态信息)
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

For server side help, type 'help contents'

mysql> status(从服务器端获取状态信息)
--------------
mysql  Ver 14.14 Distrib 5.5.28, for Linux (i686) using readline 5.1

Connection id:		8
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		5.5.28-log Source distribution
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	latin1
Db     characterset:	latin1
Client characterset:	latin1
Conn.  characterset:	latin1
UNIX socket:		/tmp/mysql.sock
Uptime:			10 hours 6 min 43 sec

Threads: 1  Questions: 46  Slow queries: 0  Opens: 37  Flush tables: 1  Open tables: 27  Queries per second avg: 0.001
--------------

mysql> USE mysql;(修改默认数据库为mysql)
Database changed
mysql> SELECT User,host FROM user;(找出user表中User字段和host字段数据)
+------+-----------------------+
| User | host                  |
+------+-----------------------+
| root | 127.0.0.1             |
| root | localhost             |
| root | localhost.localdomain |
+------+-----------------------+
3 rows in set (0.01 sec)

mysql> SELECT User,host FROM us\c(mysql语句写到一部分不想执行使用\c提前结束语句)
mysql> SELECT User,host FROM user;\c(如果前面使用;分号再使用\c提前结束语句无法结束)
+------+-----------------------+
| User | host                  |
+------+-----------------------+
| root | 127.0.0.1             |
| root | localhost             |
| root | localhost.localdomain |
+------+-----------------------+
3 rows in set (0.00 sec)

mysql> SELECT User,host FROM\c(mysql语句写到一部分不想执行使用\c提前结束语句)

mysql> \?(查看mysql客户端命令)

For information about MySQL products and services, visit:
   http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
   http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
   https://shop.mysql.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.(重新连接到服务器)
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.()
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

For server side help, type 'help contents'

mysql>\r(重新连接到Mysql)
Connection id:    9(连接id号)
Current database: mysql(显示正在打开的数据库)

mysql> \d //(更改mysql语句结束符为//双斜线)
mysql> SELECT * FROM user;(找出user表中所有字段数据,分号不执行)
    -> .(.点不执行)
    -> \C
ERROR: 
Usage: \C charset_name | charset charset_name
    -> \c
mysql> SELECT * FROM user\G(\G无论语句结束符是什么,直接将此语句送到服务器端执行,而且结果以竖排方式显示)
*************************** 1. row ***************************
                  Host: localhost
                  User: root
              Password: *84BB5DF4823DA319BBF86C99624479A198E6EEE9
           Select_priv: Y
           Insert_priv: Y
           Update_priv: Y
           Delete_priv: Y
           Create_priv: Y
             Drop_priv: Y
           Reload_priv: Y
         Shutdown_priv: Y
          Process_priv: Y
             File_priv: Y
            Grant_priv: Y
       References_priv: Y
            Index_priv: Y
            Alter_priv: Y
          Show_db_priv: Y
            Super_priv: Y
 Create_tmp_table_priv: Y
      Lock_tables_priv: Y
          Execute_priv: Y
       Repl_slave_priv: Y
      Repl_client_priv: Y
      Create_view_priv: Y
        Show_view_priv: Y
   Create_routine_priv: Y
    Alter_routine_priv: Y
      Create_user_priv: Y
            Event_priv: Y
          Trigger_priv: Y
Create_tablespace_priv: Y
              ssl_type: 
            ssl_cipher: 
           x509_issuer: 
          x509_subject: 
         max_questions: 0
           max_updates: 0
       max_connections: 0
  max_user_connections: 0
                plugin: 
 authentication_string: 
*************************** 2. row ***************************
                  Host: localhost.localdomain
                  User: root
              Password: *84BB5DF4823DA319BBF86C99624479A198E6EEE9
           Select_priv: Y
           Insert_priv: Y
           Update_priv: Y
           Delete_priv: Y
           Create_priv: Y
             Drop_priv: Y
           Reload_priv: Y
         Shutdown_priv: Y
          Process_priv: Y
             File_priv: Y
            Grant_priv: Y
       References_priv: Y
            Index_priv: Y
            Alter_priv: Y
          Show_db_priv: Y
            Super_priv: Y
 Create_tmp_table_priv: Y
      Lock_tables_priv: Y
          Execute_priv: Y
       Repl_slave_priv: Y
      Repl_client_priv: Y
      Create_view_priv: Y
        Show_view_priv: Y
   Create_routine_priv: Y
    Alter_routine_priv: Y
      Create_user_priv: Y
            Event_priv: Y
          Trigger_priv: Y
Create_tablespace_priv: Y
              ssl_type: 
            ssl_cipher: 
           x509_issuer: 
          x509_subject: 
         max_questions: 0
           max_updates: 0
       max_connections: 0
  max_user_connections: 0
                plugin: 
 authentication_string: 
*************************** 3. row ***************************
                  Host: 127.0.0.1
                  User: root
              Password: *84BB5DF4823DA319BBF86C99624479A198E6EEE9
           Select_priv: Y
           Insert_priv: Y
           Update_priv: Y
           Delete_priv: Y
           Create_priv: Y
             Drop_priv: Y
           Reload_priv: Y
         Shutdown_priv: Y
          Process_priv: Y
             File_priv: Y
            Grant_priv: Y
       References_priv: Y
            Index_priv: Y
            Alter_priv: Y
          Show_db_priv: Y
            Super_priv: Y
 Create_tmp_table_priv: Y
      Lock_tables_priv: Y
          Execute_priv: Y
       Repl_slave_priv: Y
      Repl_client_priv: Y
      Create_view_priv: Y
        Show_view_priv: Y
   Create_routine_priv: Y
    Alter_routine_priv: Y
      Create_user_priv: Y
            Event_priv: Y
          Trigger_priv: Y
Create_tablespace_priv: Y
              ssl_type: 
            ssl_cipher: 
           x509_issuer: 
          x509_subject: 
         max_questions: 0
           max_updates: 0
       max_connections: 0
  max_user_connections: 0
                plugin: 
 authentication_string: 
3 rows in set (0.00 sec)

mysql> SELECT * FROM user\g(使用\g一定会执行,当忘记语句结束符是什么时候使用)
+-----------------------+------+-------------------------------------------+-------------+-------------+-------------+-------------
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv 
+-----------------------+------+-------------------------------------------+-------------+-------------+-------------+-------------
| localhost | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 | Y | Y | Y | Y 
| localhost.localdomain | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 | Y | Y | Y | Y 
| 127.0.0.1 | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 | Y | Y | Y | Y 
+-----------------------+------+-------------------------------------------+-------------+-------------+-------------+-------------
+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+---
| Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Al
+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+---
| Y | Y | Y | Y | Y | Y | Y | Y | Y | Y 
| Y | Y | Y | Y | Y | Y | Y | Y | Y | Y 
| Y | Y | Y | Y | Y | Y | Y | Y | Y | Y 
+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+---
---------+--------------+------------+-----------------------+------------------+--------------+-----------------+-----------------
ter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv
---------+--------------+------------+-----------------------+------------------+--------------+-----------------+-----------------
| Y | Y | Y | Y | Y | Y | Y 
| Y | Y | Y | Y | Y | Y | Y 
| Y | Y | Y | Y | Y | Y | Y 
---------+--------------+------------+-----------------------+------------------+--------------+-----------------+-----------------
-+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+---
| Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Cr
-+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+---
| Y | Y | Y | Y | Y | Y | Y | Y 
| Y | Y | Y | Y | Y | Y | Y | Y 
| Y | Y | Y | Y | Y | Y | Y | Y 
-+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+---
---------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+--------
eate_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_use
---------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+--------
| | | | | 0 | 0 | 0 | 
| | | | | 0 | 0 | 0 | 
| | | | | 0 | 0 | 0 | 
---------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+--------
--------------+--------+-----------------------+
r_connections | plugin | authentication_string |
--------------+--------+-----------------------+
0 | | |
0 | | | 
0 | | | 
--------------+--------+-----------------------+
3 rows in set (0.00 sec)

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right
 syntax to use near '.
SELECT * FROM user' at line 1

mysql> \?(查看mysql客户端命令)

For information about MySQL products and services, visit:
   http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
   http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
   https://shop.mysql.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.(显示当前正在执行命令)
prompt    (\R) Change your mysql prompt.(改变mysql提示符mysql>)
quit      (\q) Quit mysql.(退出)
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.(导入mysql脚步)
status    (\s) Get status information from the server.(从服务器获取状态信息)
system    (\!) Execute a system shell command.(执行shell命令的,不需要退出mysql)
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.(在每个语句执行之后显示警告信息)
nowarning (\w) Don't show warnings after every statement.(在语句执行之后不显示警告信息)

For server side help, type 'help contents'

mysql> \p(显示当前正在执行的命令)
--------------

--------------

mysql> \! ls /root(\!执行shell命令,不需要退出mysql,显示/root目录文件及子目录)
anaconda-ks.cfg  cmake-2.8.8.tar.gz  install.log.syslog  mysql-5.5.28.tar.gz
cmake-2.8.8	 install.log	     mysql-5.5.28	 test.sql

mysql> \q(退出)
Bye

[root@localhost ~]# mysql(连接mysql)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> USE mysql;
Database changed(默认已经使用了-A选项,没有做hash)
mysql> rehash(启用mysql对新建对象命令补全功能,以后建立的数据库都可以使用名次补全)
mysql> SELECT User,Host FROM user;(找出user表中user、Host字段的数据)
+------+-----------------------+
| User | Host                  |
+------+-----------------------+
| root | 127.0.0.1             |
| root | localhost             |
| root | localhost.localdomain |
+------+-----------------------+
3 rows in set (0.00 sec)

mysql> \q(退出mysql)
Bye

[root@localhost ~]# mysql --html(连接mysql数据库,--html输出方式显示为html格式)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> USE mysql;(改变默认数据库为mysql)
Database changed
mysql> SELECT User,Host FROM user;(找出user表User、Host字段的数据)
<TABLE BORDER=1><TR><TH>User</TH><TH>Host</TH></TR><TR><TD>root</TD><TD>127.0.0.1</TD></TR><TR><TD>root</TD><TD>localhost</TD></TR><TR>
<TD>root</TD><TD>localhost.localdomain</TD></TR></TABLE>3 rows in set (0.00 sec)

提示:这是html格式的表中输出的数据,将这些内容复制到一个Html格式文件里面,他默认就是Html页面了;

测试:通过Windows系统新建文本文档,将
<TABLE BORDER=1><TR><TH>User</TH><TH>Host</TH></TR><TR><TD>root</TD><TD>127.0.0.1</TD></TR><TR><TD>root</TD><TD>localhost</TD></TR><TR><TD>root</TD><TD>localhost.localdomain</TD></TR></TABLE>内容复制进去,更改文本文档后缀为.html,然后通过浏览器打开;

mysql> help SELECT(查看SELECT命令帮助)
Name: 'SELECT'
Description:
Syntax:
SELECT
    [ALL | DISTINCT | DISTINCTROW ]
      [HIGH_PRIORITY]
      [STRAIGHT_JOIN]
      [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
      [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
    select_expr [, select_expr ...]
    [FROM table_references
    [WHERE where_condition]
    [GROUP BY {col_name | expr | position}
      [ASC | DESC], ... [WITH ROLLUP]]
    [HAVING where_condition]
    [ORDER BY {col_name | expr | position}
      [ASC | DESC], ...]
    [LIMIT {[offset,] row_count | row_count OFFSET offset}]
    [PROCEDURE procedure_name(argument_list)]
    [INTO OUTFILE 'file_name'
        [CHARACTER SET charset_name]
        export_options
      | INTO DUMPFILE 'file_name'
      | INTO var_name [, var_name]]
    [FOR UPDATE | LOCK IN SHARE MODE]]

SELECT is used to retrieve rows selected from one or more tables, and
can include UNION statements and subqueries. See [HELP UNION], and
http://dev.mysql.com/doc/refman/5.5/en/subqueries.html.

The most commonly used clauses of SELECT statements are these:

o Each select_expr indicates a column that you want to retrieve. There
  must be at least one select_expr.

o table_references indicates the table or tables from which to retrieve
  rows. Its syntax is described in [HELP JOIN].

o The WHERE clause, if given, indicates the condition or conditions
  that rows must satisfy to be selected. where_condition is an
  expression that evaluates to true for each row to be selected. The
  statement selects all rows if there is no WHERE clause.

  In the WHERE expression, you can use any of the functions and
  operators that MySQL supports, except for aggregate (summary)
  functions. See
  http://dev.mysql.com/doc/refman/5.5/en/expressions.html, and
  http://dev.mysql.com/doc/refman/5.5/en/functions.html.

SELECT can also be used to retrieve rows computed without reference to
any table.

URL: http://dev.mysql.com/doc/refman/5.5/en/select.html

mysql> help CREATE INDEX(查看创建索引的帮助)
Name: 'CREATE INDEX'
Description:
Syntax:
CREATE [ONLINE|OFFLINE] [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name
    [index_type]
    ON tbl_name (index_col_name,...)
    [index_option] ...

index_col_name:
    col_name [(length)] [ASC | DESC]

index_type:
    USING {BTREE | HASH}

index_option:
    KEY_BLOCK_SIZE [=] value
  | index_type
  | WITH PARSER parser_name
  | COMMENT 'string'

CREATE INDEX is mapped to an ALTER TABLE statement to create indexes.
See [HELP ALTER TABLE]. CREATE INDEX cannot be used to create a PRIMARY
KEY; use ALTER TABLE instead. For more information about indexes, see
http://dev.mysql.com/doc/refman/5.5/en/mysql-indexes.html.

URL: http://dev.mysql.com/doc/refman/5.5/en/create-index.html

mysql> \q(退出)
Bye

[root@localhost ~]# mysqladmin create hellodb(创建hellodb数据库)
[root@localhost ~]# mysql(连接mysql数据库)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.5.28-log Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW DATABASES;(显示数据库)
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hellodb            |
| mydb               |
| mysql              |
| performance_schema |
| test               |
| testdb             |
+--------------------+
7 rows in set (0.00 sec)

提示:有创建的hellodb数据库;

mysql> \q(退出)
Bye

[root@localhost ~]# mysqladmin ping(测试mysql服务器是否在线)
mysqld is alive(在线)
[root@localhost ~]# mysqladmin -uroot -p -h172.16.0.1 ping(测试mysql数据库是否在线,-u指定用户,-p指定密码,-h指定主机)
Enter password: 
mysqladmin: connect to server at '172.16.0.1' failed
error: 'Can't connect to MySQL server on '172.16.0.1' (111)'
Check that mysqld is running on 172.16.0.1 and that the port is 3306.
You can check this by doing 'telnet 172.16.0.1 3306'
[root@localhost ~]# mysqladmin processlist(列出mysql服务器上正在执行的mysql线程)
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 16 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
[root@localhost ~]# mysqladmin status(显示mysql服务器状态信息)
Uptime: 43701(启动时间)  Threads: 1(允许线程数)  Questions: 103(已经完成的查询数)  Slow queries: 0(慢查询的次数)  Opens: 51(打开的表数)  
Flush tables: 1(刷新的表数)  Open tables: 41(打开的文件数)  Queries per second avg: 0.002(平均美每秒的查询数)
[root@localhost ~]# mysqladmin status --sleep 2(显示mysql服务器状态信息,--sleep每睡眠多少秒显示一次)
Uptime: 45410  Threads: 1  Questions: 104  Slow queries: 0  Opens: 51  Flush tables: 1  Open tables: 41  Queries per second avg: 0.002
Uptime: 45412  Threads: 1  Questions: 104  Slow queries: 0  Opens: 51  Flush tables: 1  Open tables: 41  Queries per second avg: 0.002
Uptime: 45414  Threads: 1  Questions: 104  Slow queries: 0  Opens: 51  Flush tables: 1  Open tables: 41  Queries per second avg: 0.002
Uptime: 45416  Threads: 1  Questions: 104  Slow queries: 0  Opens: 51  Flush tables: 1  Open tables: 41  Queries per second avg: 0.002
[root@localhost ~]# mysqladmin status --sleep 2 --count 2(显示mysql服务器状态信息,--sleep每睡眠多少秒显示一次,--count最多显示多少次)
Uptime: 45503  Threads: 1  Questions: 105  Slow queries: 0  Opens: 51  Flush tables: 1  Open tables: 41  Queries per second avg: 0.002
Uptime: 45505  Threads: 1  Questions: 105  Slow queries: 0  Opens: 51  Flush tables: 1  Open tables: 41  Queries per second avg: 0.002
[root@localhost ~]# mysqladmin extended-status(查看mysql扩展状态,mysql状态变量)
+------------------------------------------+-------------+
| Variable_name                            | Value       |
+------------------------------------------+-------------+
| Aborted_clients                          | 0           |
| Aborted_connects                         | 0           |
| Binlog_cache_disk_use                    | 0           |
| Binlog_cache_use                         | 0           |
| Binlog_stmt_cache_disk_use               | 0           |
| Binlog_stmt_cache_use                    | 0           |
| Bytes_received                           | 4018        |
| Bytes_sent                               | 35501       |
| Com_admin_commands                       | 1           |
| Com_assign_to_keycache                   | 0           |
| Com_alter_db                             | 0           |
| Com_alter_db_upgrade                     | 0           |
| Com_alter_event                          | 0           |
| Com_alter_function                       | 0           |
| Com_alter_procedure                      | 0           |
| Com_alter_server                         | 0           |
| Com_alter_table                          | 0           |
| Com_alter_tablespace                     | 0           |
| Com_analyze                              | 0           |
| Com_begin                                | 0           |
| Com_binlog                               | 0           |
| Com_call_procedure                       | 0           |
| Com_change_db                            | 6           |
| Com_change_master                        | 0           |
| Com_check                                | 0           |
| Com_checksum                             | 0           |
| Com_commit                               | 0           |
| Com_create_db                            | 4           |
| Com_create_event                         | 0           |
| Com_create_function                      | 0           |
| Com_create_index                         | 0           |
| Com_create_procedure                     | 0           |
| Com_create_server                        | 0           |
| Com_create_table                         | 3           |
| Com_create_trigger                       | 0           |
| Com_create_udf                           | 0           |
| Com_create_user                          | 0           |
| Com_create_view                          | 0           |
| Com_dealloc_sql                          | 0           |
| Com_delete                               | 0           |
| Com_delete_multi                         | 0           |
| Com_do                                   | 0           |
| Com_drop_db                              | 1           |
| Com_drop_event                           | 0           |
| Com_drop_function                        | 0           |
| Com_drop_index                           | 0           |
| Com_drop_procedure                       | 0           |
| Com_drop_server                          | 0           |
| Com_drop_table                           | 0           |
| Com_drop_trigger                         | 0           |
| Com_drop_user                            | 0           |
| Com_drop_view                            | 0           |
| Com_empty_query                          | 0           |
| Com_execute_sql                          | 0           |
| Com_flush                                | 0           |
| Com_grant                                | 0           |
| Com_ha_close                             | 0           |
| Com_ha_open                              | 0           |
| Com_ha_read                              | 0           |
| Com_help                                 | 2           |
| Com_insert                               | 0           |
| Com_insert_select                        | 0           |
| Com_install_plugin                       | 0           |
| Com_kill                                 | 0           |
| Com_load                                 | 0           |
| Com_lock_tables                          | 0           |
| Com_optimize                             | 0           |
| Com_preload_keys                         | 0           |
| Com_prepare_sql                          | 0           |
| Com_purge                                | 0           |
| Com_purge_before_date                    | 0           |
| Com_release_savepoint                    | 0           |
| Com_rename_table                         | 0           |
| Com_rename_user                          | 0           |
| Com_repair                               | 0           |
| Com_replace                              | 0           |
| Com_replace_select                       | 0           |
| Com_reset                                | 0           |
| Com_resignal                             | 0           |
| Com_revoke                               | 0           |
| Com_revoke_all                           | 0           |
| Com_rollback                             | 0           |
| Com_rollback_to_savepoint                | 0           |
| Com_savepoint                            | 0           |
| Com_select                               | 31          |
| Com_set_option                           | 0           |
| Com_signal                               | 0           |
| Com_show_authors                         | 0           |
| Com_show_binlog_events                   | 0           |
| Com_show_binlogs                         | 0           |
| Com_show_charsets                        | 0           |
| Com_show_collations                      | 0           |
| Com_show_contributors                    | 0           |
| Com_show_create_db                       | 0           |
| Com_show_create_event                    | 0           |
| Com_show_create_func                     | 0           |
| Com_show_create_proc                     | 0           |
| Com_show_create_table                    | 0           |
| Com_show_create_trigger                  | 0           |
| Com_show_databases                       | 8           |
| Com_show_engine_logs                     | 0           |
| Com_show_engine_mutex                    | 0           |
| Com_show_engine_status                   | 0           |
| Com_show_events                          | 0           |
| Com_show_errors                          | 0           |
| Com_show_fields                          | 24          |
| Com_show_function_status                 | 0           |
| Com_show_grants                          | 0           |
| Com_show_keys                            | 0           |
| Com_show_master_status                   | 0           |
| Com_show_open_tables                     | 0           |
| Com_show_plugins                         | 0           |
| Com_show_privileges                      | 0           |
| Com_show_procedure_status                | 0           |
| Com_show_processlist                     | 1           |
| Com_show_profile                         | 0           |
| Com_show_profiles                        | 0           |
| Com_show_relaylog_events                 | 0           |
| Com_show_slave_hosts                     | 0           |
| Com_show_slave_status                    | 0           |
| Com_show_status                          | 9           |
| Com_show_storage_engines                 | 0           |
| Com_show_table_status                    | 0           |
| Com_show_tables                          | 2           |
| Com_show_triggers                        | 0           |
| Com_show_variables                       | 1           |
| Com_show_warnings                        | 0           |
| Com_slave_start                          | 0           |
| Com_slave_stop                           | 0           |
| Com_stmt_close                           | 0           |
| Com_stmt_execute                         | 0           |
| Com_stmt_fetch                           | 0           |
| Com_stmt_prepare                         | 0           |
| Com_stmt_reprepare                       | 0           |
| Com_stmt_reset                           | 0           |
| Com_stmt_send_long_data                  | 0           |
| Com_truncate                             | 0           |
| Com_uninstall_plugin                     | 0           |
| Com_unlock_tables                        | 0           |
| Com_update                               | 0           |
| Com_update_multi                         | 0           |
| Com_xa_commit                            | 0           |
| Com_xa_end                               | 0           |
| Com_xa_prepare                           | 0           |
| Com_xa_recover                           | 0           |
| Com_xa_rollback                          | 0           |
| Com_xa_start                             | 0           |
| Compression                              | OFF         |
| Connections                              | 21          |
| Created_tmp_disk_tables                  | 0           |
| Created_tmp_files                        | 5           |
| Created_tmp_tables                       | 12          |
| Delayed_errors                           | 0           |
| Delayed_insert_threads                   | 0           |
| Delayed_writes                           | 0           |
| Flush_commands                           | 1           |
| Handler_commit                           | 0           |
| Handler_delete                           | 0           |
| Handler_discover                         | 0           |
| Handler_prepare                          | 0           |
| Handler_read_first                       | 7           |
| Handler_read_key                         | 5           |
| Handler_read_last                        | 0           |
| Handler_read_next                        | 12          |
| Handler_read_prev                        | 0           |
| Handler_read_rnd                         | 0           |
| Handler_read_rnd_next                    | 169         |
| Handler_rollback                         | 0           |
| Handler_savepoint                        | 0           |
| Handler_savepoint_rollback               | 0           |
| Handler_update                           | 0           |
| Handler_write                            | 134         |
| Innodb_buffer_pool_pages_data            | 159         |
| Innodb_buffer_pool_pages_dirty           | 0           |
| Innodb_buffer_pool_pages_flushed         | 45          |
| Innodb_buffer_pool_pages_free            | 8031        |
| Innodb_buffer_pool_pages_misc            | 1           |
| Innodb_buffer_pool_pages_total           | 8191        |
| Innodb_buffer_pool_read_ahead_rnd        | 0           |
| Innodb_buffer_pool_read_ahead            | 0           |
| Innodb_buffer_pool_read_ahead_evicted    | 0           |
| Innodb_buffer_pool_read_requests         | 694         |
| Innodb_buffer_pool_reads                 | 145         |
| Innodb_buffer_pool_wait_free             | 0           |
| Innodb_buffer_pool_write_requests        | 142         |
| Innodb_data_fsyncs                       | 35          |
| Innodb_data_pending_fsyncs               | 0           |
| Innodb_data_pending_reads                | 0           |
| Innodb_data_pending_writes               | 0           |
| Innodb_data_read                         | 4558848     |
| Innodb_data_reads                        | 155         |
| Innodb_data_writes                       | 46          |
| Innodb_data_written                      | 1492480     |
| Innodb_dblwr_pages_written               | 45          |
| Innodb_dblwr_writes                      | 4           |
| Innodb_have_atomic_builtins              | OFF         |
| Innodb_log_waits                         | 0           |
| Innodb_log_write_requests                | 29          |
| Innodb_log_writes                        | 6           |
| Innodb_os_log_fsyncs                     | 12          |
| Innodb_os_log_pending_fsyncs             | 0           |
| Innodb_os_log_pending_writes             | 0           |
| Innodb_os_log_written                    | 14848       |
| Innodb_page_size                         | 16384       |
| Innodb_pages_created                     | 15          |
| Innodb_pages_read                        | 144         |
| Innodb_pages_written                     | 45          |
| Innodb_row_lock_current_waits            | 0           |
| Innodb_row_lock_time                     | 0           |
| Innodb_row_lock_time_avg                 | 0           |
| Innodb_row_lock_time_max                 | 0           |
| Innodb_row_lock_waits                    | 0           |
| Innodb_rows_deleted                      | 0           |
| Innodb_rows_inserted                     | 0           |
| Innodb_rows_read                         | 0           |
| Innodb_rows_updated                      | 0           |
| Innodb_truncated_status_writes           | 0           |
| Key_blocks_not_flushed                   | 0           |
| Key_blocks_unused                        | 231956      |
| Key_blocks_used                          | 4           |
| Key_read_requests                        | 12          |
| Key_reads                                | 4           |
| Key_write_requests                       | 0           |
| Key_writes                               | 0           |
| Last_query_cost                          | 0.000000    |
| Max_used_connections                     | 1           |
| Not_flushed_delayed_rows                 | 0           |
| Open_files                               | 50          |
| Open_streams                             | 0           |
| Open_table_definitions                   | 41          |
| Open_tables                              | 41          |
| Opened_files                             | 134         |
| Opened_table_definitions                 | 44          |
| Opened_tables                            | 51          |
| Performance_schema_cond_classes_lost     | 0           |
| Performance_schema_cond_instances_lost   | 0           |
| Performance_schema_file_classes_lost     | 0           |
| Performance_schema_file_handles_lost     | 0           |
| Performance_schema_file_instances_lost   | 0           |
| Performance_schema_locker_lost           | 0           |
| Performance_schema_mutex_classes_lost    | 0           |
| Performance_schema_mutex_instances_lost  | 0           |
| Performance_schema_rwlock_classes_lost   | 0           |
| Performance_schema_rwlock_instances_lost | 0           |
| Performance_schema_table_handles_lost    | 0           |
| Performance_schema_table_instances_lost  | 0           |
| Performance_schema_thread_classes_lost   | 0           |
| Performance_schema_thread_instances_lost | 0           |
| Prepared_stmt_count                      | 0           |
| Qcache_free_blocks                       | 1           |
| Qcache_free_memory                       | 16768392    |
| Qcache_hits                              | 0           |
| Qcache_inserts                           | 0           |
| Qcache_lowmem_prunes                     | 0           |
| Qcache_not_cached                        | 31          |
| Qcache_queries_in_cache                  | 0           |
| Qcache_total_blocks                      | 1           |
| Queries                                  | 106         |
| Questions                                | 106         |
| Rpl_status                               | AUTH_MASTER |
| Select_full_join                         | 0           |
| Select_full_range_join                   | 0           |
| Select_range                             | 0           |
| Select_range_check                       | 0           |
| Select_scan                              | 18          |
| Slave_heartbeat_period                   | 0.000       |
| Slave_open_temp_tables                   | 0           |
| Slave_received_heartbeats                | 0           |
| Slave_retried_transactions               | 0           |
| Slave_running                            | OFF         |
| Slow_launch_threads                      | 0           |
| Slow_queries                             | 0           |
| Sort_merge_passes                        | 0           |
| Sort_range                               | 0           |
| Sort_rows                                | 0           |
| Sort_scan                                | 0           |
| Ssl_accept_renegotiates                  | 0           |
| Ssl_accepts                              | 0           |
| Ssl_callback_cache_hits                  | 0           |
| Ssl_cipher                               |             |
| Ssl_cipher_list                          |             |
| Ssl_client_connects                      | 0           |
| Ssl_connect_renegotiates                 | 0           |
| Ssl_ctx_verify_depth                     | 0           |
| Ssl_ctx_verify_mode                      | 0           |
| Ssl_default_timeout                      | 0           |
| Ssl_finished_accepts                     | 0           |
| Ssl_finished_connects                    | 0           |
| Ssl_session_cache_hits                   | 0           |
| Ssl_session_cache_misses                 | 0           |
| Ssl_session_cache_mode                   | NONE        |
| Ssl_session_cache_overflows              | 0           |
| Ssl_session_cache_size                   | 0           |
| Ssl_session_cache_timeouts               | 0           |
| Ssl_sessions_reused                      | 0           |
| Ssl_used_session_cache_entries           | 0           |
| Ssl_verify_depth                         | 0           |
| Ssl_verify_mode                          | 0           |
| Ssl_version                              |             |
| Table_locks_immediate                    | 54          |
| Table_locks_waited                       | 0           |
| Tc_log_max_pages_used                    | 0           |
| Tc_log_page_size                         | 0           |
| Tc_log_page_waits                        | 0           |
| Threads_cached                           | 0           |
| Threads_connected                        | 1           |
| Threads_created                          | 1           |
| Threads_running                          | 1           |
| Uptime                                   | 45965       |
| Uptime_since_flush_status                | 45965       |
+------------------------------------------+-------------+
[root@localhost ~]# mysqladmin variables(mysql服务器变量)
+---------------------------------------------------+-------------------------------------------------------------------------------+
| Variable_name                                     | Value                                                                         |
+---------------------------------------------------+-------------------------------------------------------------------------------+
| auto_increment_increment                          | 1                                                                             |
| auto_increment_offset                             | 1                                                                             |
| autocommit                                        | ON                                                                            |
| automatic_sp_privileges                           | ON                                                                            |
| back_log                                          | 50                                                                            |
| basedir                                           | /usr/local/mysql                                                              |
| big_tables                                        | OFF                                                                           |
| binlog_cache_size                                 | 32768                                                                         |
| binlog_direct_non_transactional_updates           | OFF                                                                           |
| binlog_format                                     | MIXED                                                                         |
| binlog_stmt_cache_size                            | 32768                                                                         |
| bulk_insert_buffer_size                           | 8388608                                                                       |
| character_set_client                              | latin1                                                                        |
| character_set_connection                          | latin1                                                                        |
| character_set_database                            | latin1                                                                        |
| character_set_filesystem                          | binary                                                                        |
| character_set_results                             | latin1                                                                        |
| character_set_server                              | latin1                                                                        |
| character_set_system                              | utf8                                                                          |
| character_sets_dir                                | /usr/local/mysql/share/charsets/                                              |
| collation_connection                              | latin1_swedish_ci                                                             |
| collation_database                                | latin1_swedish_ci                                                             |
| collation_server                                  | latin1_swedish_ci                                                             |
| completion_type                                   | NO_CHAIN                                                                      |
| concurrent_insert                                 | AUTO                                                                          |
| connect_timeout                                   | 10                                                                            |
| datadir                                           | /mydata/data/                                                                 |
| date_format                                       | %Y-%m-%d                                                                      |
| datetime_format                                   | %Y-%m-%d %H:%i:%s                                                             |
| default_storage_engine                            | InnoDB                                                                        |
| default_week_format                               | 0                                                                             |
| delay_key_write                                   | ON                                                                            |
| delayed_insert_limit                              | 100                                                                           |
| delayed_insert_timeout                            | 300                                                                           |
| delayed_queue_size                                | 1000                                                                          |
| div_precision_increment                           | 4                                                                             |
| engine_condition_pushdown                         | ON                                                                            |
| event_scheduler                                   | OFF                                                                           |
| expire_logs_days                                  | 0                                                                             |
| flush                                             | OFF                                                                           |
| flush_time                                        | 0                                                                             |
| foreign_key_checks                                | ON                                                                            |
| ft_boolean_syntax                                 | + -><()~*:""&|                                                                |
| ft_max_word_len                                   | 84                                                                            |
| ft_min_word_len                                   | 4                                                                             |
| ft_query_expansion_limit                          | 20                                                                            |
| ft_stopword_file                                  | (built-in)                                                                    |
| general_log                                       | OFF                                                                           |
| general_log_file                                  | /mydata/data/localhost.log                                                    |
| group_concat_max_len                              | 1024                                                                          |
| have_compress                                     | YES                                                                           |
| have_crypt                                        | YES                                                                           |
| have_csv                                          | YES                                                                           |
| have_dynamic_loading                              | YES                                                                           |
| have_geometry                                     | YES                                                                           |
| have_innodb                                       | YES                                                                           |
| have_ndbcluster                                   | NO                                                                            |
| have_openssl                                      | DISABLED                                                                      |
| have_partitioning                                 | YES                                                                           |
| have_profiling                                    | YES                                                                           |
| have_query_cache                                  | YES                                                                           |
| have_rtree_keys                                   | YES                                                                           |
| have_ssl                                          | DISABLED                                                                      |
| have_symlink                                      | YES                                                                           |
| hostname                                          | localhost.localdomain                                                         |
| ignore_builtin_innodb                             | OFF                                                                           |
| init_connect                                      |                                                                               |
| init_file                                         |                                                                               |
| init_slave                                        |                                                                               |
| innodb_adaptive_flushing                          | ON                                                                            |
| innodb_adaptive_hash_index                        | ON                                                                            |
| innodb_additional_mem_pool_size                   | 8388608                                                                       |
| innodb_autoextend_increment                       | 8                                                                             |
| innodb_autoinc_lock_mode                          | 1                                                                             |
| innodb_buffer_pool_instances                      | 1                                                                             |
| innodb_buffer_pool_size                           | 134217728                                                                     |
| innodb_change_buffering                           | all                                                                           |
| innodb_checksums                                  | ON                                                                            |
| innodb_commit_concurrency                         | 0                                                                             |
| innodb_concurrency_tickets                        | 500                                                                           |
| innodb_data_file_path                             | ibdata1:10M:autoextend                                                        |
| innodb_data_home_dir                              |                                                                               |
| innodb_doublewrite                                | ON                                                                            |
| innodb_fast_shutdown                              | 1                                                                             |
| innodb_file_format                                | Antelope                                                                      |
| innodb_file_format_check                          | ON                                                                            |
| innodb_file_format_max                            | Antelope                                                                      |
| innodb_file_per_table                             | ON                                                                            |
| innodb_flush_log_at_trx_commit                    | 1                                                                             |
| innodb_flush_method                               |                                                                               |
| innodb_force_load_corrupted                       | OFF                                                                           |
| innodb_force_recovery                             | 0                                                                             |
| innodb_io_capacity                                | 200                                                                           |
| innodb_large_prefix                               | OFF                                                                           |
| innodb_lock_wait_timeout                          | 50                                                                            |
| innodb_locks_unsafe_for_binlog                    | OFF                                                                           |
| innodb_log_buffer_size                            | 8388608                                                                       |
| innodb_log_file_size                              | 5242880                                                                       |
| innodb_log_files_in_group                         | 2                                                                             |
| innodb_log_group_home_dir                         | ./                                                                            |
| innodb_max_dirty_pages_pct                        | 75                                                                            |
| innodb_max_purge_lag                              | 0                                                                             |
| innodb_mirrored_log_groups                        | 1                                                                             |
| innodb_old_blocks_pct                             | 37                                                                            |
| innodb_old_blocks_time                            | 0                                                                             |
| innodb_open_files                                 | 300                                                                           |
| innodb_purge_batch_size                           | 20                                                                            |
| innodb_purge_threads                              | 0                                                                             |
| innodb_random_read_ahead                          | OFF                                                                           |
| innodb_read_ahead_threshold                       | 56                                                                            |
| innodb_read_io_threads                            | 4                                                                             |
| innodb_replication_delay                          | 0                                                                             |
| innodb_rollback_on_timeout                        | OFF                                                                           |
| innodb_rollback_segments                          | 128                                                                           |
| innodb_spin_wait_delay                            | 6                                                                             |
| innodb_stats_method                               | nulls_equal                                                                   |
| innodb_stats_on_metadata                          | ON                                                                            |
| innodb_stats_sample_pages                         | 8                                                                             |
| innodb_strict_mode                                | OFF                                                                           |
| innodb_support_xa                                 | ON                                                                            |
| innodb_sync_spin_loops                            | 30                                                                            |
| innodb_table_locks                                | ON                                                                            |
| innodb_thread_concurrency                         | 0                                                                             |
| innodb_thread_sleep_delay                         | 10000                                                                         |
| innodb_use_native_aio                             | OFF                                                                           |
| innodb_use_sys_malloc                             | ON                                                                            |
| innodb_version                                    | 1.1.8                                                                         |
| innodb_write_io_threads                           | 4                                                                             |
| interactive_timeout                               | 28800                                                                         |
| join_buffer_size                                  | 131072                                                                        |
| keep_files_on_create                              | OFF                                                                           |
| key_buffer_size                                   | 268435456                                                                     |
| key_cache_age_threshold                           | 300                                                                           |
| key_cache_block_size                              | 1024                                                                          |
| key_cache_division_limit                          | 100                                                                           |
| large_files_support                               | ON                                                                            |
| large_page_size                                   | 0                                                                             |
| large_pages                                       | OFF                                                                           |
| lc_messages                                       | en_US                                                                         |
| lc_messages_dir                                   | /usr/local/mysql/share/                                                       |
| lc_time_names                                     | en_US                                                                         |
| license                                           | GPL                                                                           |
| local_infile                                      | ON                                                                            |
| lock_wait_timeout                                 | 31536000                                                                      |
| locked_in_memory                                  | OFF                                                                           |
| log                                               | OFF                                                                           |
| log_bin                                           | ON                                                                            |
| log_bin_trust_function_creators                   | OFF                                                                           |
| log_error                                         | /mydata/data/localhost.localdomain.err                                        |
| log_output                                        | FILE                                                                          |
| log_queries_not_using_indexes                     | OFF                                                                           |
| log_slave_updates                                 | OFF                                                                           |
| log_slow_queries                                  | OFF                                                                           |
| log_warnings                                      | 1                                                                             |
| long_query_time                                   | 10.000000                                                                     |
| low_priority_updates                              | OFF                                                                           |
| lower_case_file_system                            | OFF                                                                           |
| lower_case_table_names                            | 0                                                                             |
| max_allowed_packet                                | 1048576                                                                       |
| max_binlog_cache_size                             | 18446744073709547520                                                          |
| max_binlog_size                                   | 1073741824                                                                    |
| max_binlog_stmt_cache_size                        | 18446744073709547520                                                          |
| max_connect_errors                                | 10                                                                            |
| max_connections                                   | 151                                                                           |
| max_delayed_threads                               | 20                                                                            |
| max_error_count                                   | 64                                                                            |
| max_heap_table_size                               | 16777216                                                                      |
| max_insert_delayed_threads                        | 20                                                                            |
| max_join_size                                     | 18446744073709551615                                                          |
| max_length_for_sort_data                          | 1024                                                                          |
| max_long_data_size                                | 1048576                                                                       |
| max_prepared_stmt_count                           | 16382                                                                         |
| max_relay_log_size                                | 0                                                                             |
| max_seeks_for_key                                 | 4294967295                                                                    |
| max_sort_length                                   | 1024                                                                          |
| max_sp_recursion_depth                            | 0                                                                             |
| max_tmp_tables                                    | 32                                                                            |
| max_user_connections                              | 0                                                                             |
| max_write_lock_count                              | 4294967295                                                                    |
| metadata_locks_cache_size                         | 1024                                                                          |
| min_examined_row_limit                            | 0                                                                             |
| multi_range_count                                 | 256                                                                           |
| myisam_data_pointer_size                          | 6                                                                             |
| myisam_max_sort_file_size                         | 2146435072                                                                    |
| myisam_mmap_size                                  | 4294967295                                                                    |
| myisam_recover_options                            | OFF                                                                           |
| myisam_repair_threads                             | 1                                                                             |
| myisam_sort_buffer_size                           | 67108864                                                                      |
| myisam_stats_method                               | nulls_unequal                                                                 |
| myisam_use_mmap                                   | OFF                                                                           |
| net_buffer_length                                 | 16384                                                                         |
| net_read_timeout                                  | 30                                                                            |
| net_retry_count                                   | 10                                                                            |
| net_write_timeout                                 | 60                                                                            |
| new                                               | OFF                                                                           |
| old                                               | OFF                                                                           |
| old_alter_table                                   | OFF                                                                           |
| old_passwords                                     | OFF                                                                           |
| open_files_limit                                  | 1024                                                                          |
| optimizer_prune_level                             | 1                                                                             |
| optimizer_search_depth                            | 62                                                                            |
| optimizer_switch                                  | index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_in  |
tersection=on,engine_condition_pushdown=on                                                                                          |
| performance_schema                                | OFF                                                                           |
| performance_schema_events_waits_history_long_size | 10000                                                                         |
| performance_schema_events_waits_history_size      | 10                                                                            |
| performance_schema_max_cond_classes               | 80                                                                            |
| performance_schema_max_cond_instances             | 1000                                                                          |
| performance_schema_max_file_classes               | 50                                                                            |
| performance_schema_max_file_handles               | 32768                                                                         |
| performance_schema_max_file_instances             | 10000                                                                         |
| performance_schema_max_mutex_classes              | 200                                                                           |
| performance_schema_max_mutex_instances            | 1000000                                                                       |
| performance_schema_max_rwlock_classes             | 30                                                                            |
| performance_schema_max_rwlock_instances           | 1000000                                                                       |
| performance_schema_max_table_handles              | 100000                                                                        |
| performance_schema_max_table_instances            | 50000                                                                         |
| performance_schema_max_thread_classes             | 50                                                                            |
| performance_schema_max_thread_instances           | 1000                                                                          |
| pid_file                                          | /mydata/data/localhost.localdomain.pid                                        |
| plugin_dir                                        | /usr/local/mysql/lib/plugin/                                                  |
| port                                              | 3306                                                                          |
| preload_buffer_size                               | 32768                                                                         |
| profiling                                         | OFF                                                                           |
| profiling_history_size                            | 15                                                                            |
| protocol_version                                  | 10                                                                            |
| query_alloc_block_size                            | 8192                                                                          |
| query_cache_limit                                 | 1048576                                                                       |
| query_cache_min_res_unit                          | 4096                                                                          |
| query_cache_size                                  | 16777216                                                                      |
| query_cache_type                                  | ON                                                                            |
| query_cache_wlock_invalidate                      | OFF                                                                           |
| query_prealloc_size                               | 8192                                                                          |
| range_alloc_block_size                            | 4096                                                                          |
| read_buffer_size                                  | 1048576                                                                       |
| read_only                                         | OFF                                                                           |
| read_rnd_buffer_size                              | 4194304                                                                       |
| relay_log                                         |                                                                               |
| relay_log_index                                   |                                                                               |
| relay_log_info_file                               | relay-log.info                                                                |
| relay_log_purge                                   | ON                                                                            |
| relay_log_recovery                                | OFF                                                                           |
| relay_log_space_limit                             | 0                                                                             |
| report_host                                       |                                                                               |
| report_password                                   |                                                                               |
| report_port                                       | 3306                                                                          |
| report_user                                       |                                                                               |
| rpl_recovery_rank                                 | 0                                                                             |
| secure_auth                                       | OFF                                                                           |
| secure_file_priv                                  |                                                                               |
| server_id                                         | 1                                                                             |
| skip_external_locking                             | ON                                                                            |
| skip_name_resolve                                 | OFF                                                                           |
| skip_networking                                   | OFF                                                                           |
| skip_show_database                                | OFF                                                                           |
| slave_compressed_protocol                         | OFF                                                                           |
| slave_exec_mode                                   | STRICT                                                                        |
| slave_load_tmpdir                                 | /tmp                                                                          |
| slave_max_allowed_packet                          | 1073741824                                                                    |
| slave_net_timeout                                 | 3600                                                                          |
| slave_skip_errors                                 | OFF                                                                           |
| slave_transaction_retries                         | 10                                                                            |
| slave_type_conversions                            |                                                                               |
| slow_launch_time                                  | 2                                                                             |
| slow_query_log                                    | OFF                                                                           |
| slow_query_log_file                               | /mydata/data/localhost-slow.log                                               |
| socket                                            | /tmp/mysql.sock                                                               |
| sort_buffer_size                                  | 1048576                                                                       |
| sql_auto_is_null                                  | OFF                                                                           |
| sql_big_selects                                   | ON                                                                            |
| sql_big_tables                                    | OFF                                                                           |
| sql_buffer_result                                 | OFF                                                                           |
| sql_log_bin                                       | ON                                                                            |
| sql_log_off                                       | OFF                                                                           |
| sql_low_priority_updates                          | OFF                                                                           |
| sql_max_join_size                                 | 18446744073709551615                                                          |
| sql_mode                                          |                                                                               |
| sql_notes                                         | ON                                                                            |
| sql_quote_show_create                             | ON                                                                            |
| sql_safe_updates                                  | OFF                                                                           |
| sql_select_limit                                  | 18446744073709551615                                                          |
| sql_slave_skip_counter                            | 0                                                                             |
| sql_warnings                                      | OFF                                                                           |
| ssl_ca                                            |                                                                               |
| ssl_capath                                        |                                                                               |
| ssl_cert                                          |                                                                               |
| ssl_cipher                                        |                                                                               |
| ssl_key                                           |                                                                               |
| storage_engine                                    | InnoDB                                                                        |
| stored_program_cache                              | 256                                                                           |
| sync_binlog                                       | 0                                                                             |
| sync_frm                                          | ON                                                                            |
| sync_master_info                                  | 0                                                                             |
| sync_relay_log                                    | 0                                                                             |
| sync_relay_log_info                               | 0                                                                             |
| system_time_zone                                  | CST                                                                           |
| table_definition_cache                            | 400                                                                           |
| table_open_cache                                  | 256                                                                           |
| thread_cache_size                                 | 8                                                                             |
| thread_concurrency                                | 8                                                                             |
| thread_handling                                   | one-thread-per-connection                                                     |
| thread_stack                                      | 196608                                                                        |
| time_format                                       | %H:%i:%s                                                                      |
| time_zone                                         | SYSTEM                                                                        |
| timed_mutexes                                     | OFF                                                                           |
| tmp_table_size                                    | 16777216                                                                      |
| tmpdir                                            | /tmp                                                                          |
| transaction_alloc_block_size                      | 8192                                                                          |
| transaction_prealloc_size                         | 4096                                                                          |
| tx_isolation                                      | REPEATABLE-READ                                                               |
| unique_checks                                     | ON                                                                            |
| updatable_views_with_limit                        | YES                                                                           |
| version                                           | 5.5.28-log                                                                    |
| version_comment                                   | Source distribution                                                           |
| version_compile_machine                           | i686                                                                          |
| version_compile_os                                | Linux                                                                         |
| wait_timeout                                      | 28800                                                                         |
+---------------------------------------------------+-------------------------------------------------------------------------------+
[root@localhost ~]# mysqladmin shutdown(关闭mysql服务器)
[root@localhost ~]# netstat -tnlp(查看系统服务,-t代表tcp,-n以数字显示,-l监听端口,-p协议名称)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      3494/./hpiod        
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      3175/portmap        
tcp        0      0 0.0.0.0:852                 0.0.0.0:*                   LISTEN      3214/rpc.statd      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      3515/sshd           
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      3527/cupsd          
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      3564/sendmail       
tcp        0      0 127.0.0.1:6010              0.0.0.0:*                   LISTEN      27895/sshd          
tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      3499/python         
tcp        0      0 :::22                       :::*                        LISTEN      3515/sshd           
tcp        0      0 ::1:6010                    :::*                        LISTEN      27895/sshd    
提示:3306端口没有了;
[root@localhost ~]# service mysqld start(启动mysqld服务器)
Starting MySQL..                                           [  OK  ]
[root@localhost ~]# mysqladmin version(显示mysql的版本号及状态信息)
mysqladmin  Ver 8.42 Distrib 5.5.28, for Linux on i686
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version		5.5.28-log
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/tmp/mysql.sock
Uptime:			14 min 54 sec

Threads: 1  Questions: 1  Slow queries: 0  Opens: 33  Flush tables: 1  Open tables: 26  Queries per second avg: 0.001(状态信息)