??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲欧洲日产国码久在线,亚洲AV色香蕉一区二区,亚洲三级在线视频http://www.tkk7.com/kxbin/category/49611.html成功留给有准备的?/description>zh-cnWed, 26 Sep 2012 23:46:34 GMTWed, 26 Sep 2012 23:46:34 GMT60使用INSERT语句向表中插入数据(MSSQLSERVER版)http://www.tkk7.com/kxbin/articles/387989.htmlkxbinkxbinTue, 18 Sep 2012 07:09:00 GMThttp://www.tkk7.com/kxbin/articles/387989.htmlhttp://www.tkk7.com/kxbin/comments/387989.htmlhttp://www.tkk7.com/kxbin/articles/387989.html#Feedback0http://www.tkk7.com/kxbin/comments/commentRss/387989.htmlhttp://www.tkk7.com/kxbin/services/trackbacks/387989.html阅读全文

kxbin 2012-09-18 15:09 发表评论
]]>
oracle学习W记http://www.tkk7.com/kxbin/articles/384940.htmlkxbinkxbinMon, 06 Aug 2012 12:56:00 GMThttp://www.tkk7.com/kxbin/articles/384940.htmlhttp://www.tkk7.com/kxbin/comments/384940.htmlhttp://www.tkk7.com/kxbin/articles/384940.html#Feedback0http://www.tkk7.com/kxbin/comments/commentRss/384940.htmlhttp://www.tkk7.com/kxbin/services/trackbacks/384940.html2.oracle安装会自动生成sys用户和system用户。sys用户是超U用Ph最高权限,hsysdba角色。有create database的权限,该用户默认密码是managerQsystem用户是管理操作员Q具有sysoper角色Q没有create database的权限,默认密码 change_on_install;Ҏ据库的维护一般用system用户可以了?br />3.sql*plus常用命oQ?br /> 1Q连接命?br />    conn 用户?密码@|络服务?[as sysdba/sysoper]Q当用特权用戯n份连接时Q必d上as sysdba或是as sysoper;
    disc[onnect]Q用于断开与当前数据库的连接;
    passw[ord]Q用于修改用L密码Q如果要想修改其他用L密码Q需要用sys/systemdQ?br />    show user 昄当前用户名;
    exit 断开与数据库的连接,同时退出;
 2Q文件操作命?br />    start和@Q运行sql脚本。例如:start d:\a.sql
    editQ编辑指定的sql脚本
    spoolQ将sql*plus屏幕上的内容输出到指定文件中厅R例?spool d:\aa.sql Qƈ输入 spool off?br /> 3Q显C和讄环境变量
     linesizeQ设|显C的宽度,默认?0个字W。例如:show linesizeQset linesize 90Q?br />     pagesizeQ设|每|C的行数目,默认?4?br />4.用户理
 1Q创建用?create user xiaohuang identified by m123Qxiaohuang用户名,m123密码Q密码不能以数字开头。具有dba的权限才能创建用P
 2Q修改密?如果l自׃改密码直接用 password 用户名;如果l别Z改密?alter user xiaohuang indentified by m345Q必d有dba权限的h才能修改?br /> 3Q删除用P需hdrop user 权限Qdrop user 用户?cascade。cascadeU联删除Q如果已l创则一q删除?br />5.权限理分ؓpȝ权限和对象权?br /> 1Q系l权限,用户Ҏ据库的相x限(执行特定cdsql命o的权利,用于控制用户执行一个或一l数据库操作。常见系l权限包括create session q接数据库;create view 创徏视图Qcreate procedure 创徏q程、函数、包Qcreate table 创徏表)Q查询数据字典视图system_privilege_mapQ获得权限信息;收回pȝ权限 revoke create session from 用户?Q收回用户名1的连接数据库的权限;
 2Q对象权限,用户对其他用L数据对象操作的权限。常见对象权限包括alter修改表结构;delete删除数据Qupdate修改数据Qselect 查询数据Qinsert插入数据Qindex在表上徏立烦引;references 引用Qexecute执行Q?br />   对用戯问权限更加精l控?grant update on emp(sal) to 用户名;回收权限revoke select on emp from 用户?br /> 3Q对象权限的传?grant select on emp to 用户? with grant option
 4Q系l权限的传?grant connect to 用户? with admin option
6.角色Q一l权限的集合。分为预定义角色和自定义角色。徏立权限的理
 1Q预定义角色分类Qdba拥有全部权限Q是pȝ最高权限,只有dba才可以创建数据库l构Qresource只可以创建实体,不可以创建数据库l构Qconnect可以doracleQ不可以创徏实体Q也不可以创建数据库l构。对于普通用P授予connectQresource权限Q对于dba理用户Q授予connectQresourceQdba权限?br /> 2Q自定义角色。徏立角Ԍ不验证)Q如果角色是公用的角Ԍ可以采用不验证的方式建立角色 create role 角色?not identified;建立角色(数据库验?Q采用这L方式Q角色名、口令存攑֜数据库中。当Ȁz该角色Ӟ必须提供口o。在建立q种角色Ӟ需要ؓ其提供口?create role 角色?identified by shunping.
  3Q自定义角色授权Q当建立角色Ӟ角色没有M权限Q给角色授予权限和给用户授予权限没有太多区别Q但是要注意Q系l权限的unlimited tablespace和对象权限的with grant option 选项不能授予角色的。grant select on scott.emp to 角色名;grant create session to 角色?with admin option;
  4)把角色赋l用?grant 角色?to 用户?with admin option;
  5)删除角色 drop role 角色?br />7.profile理用户口o
 1Qprofile是口令限Ӟ资源限制的命令集合,当徏立数据库Ӟoracle会自动徏立名UCؓdefault的profile。当建立用户没有指定profile选项Q那oracle会将default分配l用戗?br /> 2Q̎号锁定,指定该̎L录时最多可以输入密码的ơ数Q也可以指定用户锁定的时_天)一般用dba的n份去执行该命令;例如指定teaq个用户最多只能尝?ơ登录,锁定旉?天。创建profile文gQ?span style="color: red; ">create profile lock_account limit failed_login_attempts 3 password_lock_time 2; alter user tea profile lock_account.
 3Q给账号解锁 alter user tea account unlockQ?br /> 4Q终止口?br />      Z让用户定期修改密码可以用终止口令的指o来完成,同样q个命o也需要dbaw䆾来操作?br />      例如Q给用户tea创徏一个profile文gQ要求改用户每隔10天要修改自家的登录密码,宽限期ؓ2天?span style="color: red; ">create profile myprofile limit password_left_time 10 password_grace_time 2Qalter user tea profile myprofile?br /> 5Q口令历?br />     如果希望用户在修改密码时Q不能用以前用过的密码,可用口令历Ԍq样oracle׃口令修改的信息存放到数据字怸Q这样当用户修改密码Ӟoracle׃Ҏ旧密码进行比较,当发现新旧密码一hQ就提示用户重新输入密码?br />     例子Q?span style="color: red; ">create profile password_history limit password_life_time 10 password_grace_time 2 password_reuse_time 10。password_reuse_time //指定口o可重用时间即10天后可以重用?br /> 6Q删除profile drop profile password_history [cascade] U联删除?br />8.oracle数据cd
   1.charQ定长,最?000字符Q汉字占2个字W。查询效率比varcharcdQ插入的数据不则自动补全;
   2.varcharQ变长,最?000字符Q?br />   3.clobQ字W型大对象,最?GQ?br />9.保存?
   1)savepoint aa 创徏保存点;
   2Qrollback to aa 回滚。如果已l提交commitQ则保存点不存在Q不能再使用回滚。rollback 回滚所有事?
10.删除数据
   1Qdelete from student。删除所有记录,表结构还在,写日志,可以恢复的。速度慢;
   2Qdrop table student。删除表的结构和数据Q?br />   3Qtruncate table student 删除表中的所有记录,表结构还在,不写日志Q无法找回删除的记录Q速度快;
11.只读事务
    指只允许执行查询的操作,而不允许执行M其他dml操作的事务。用只M务可以确保用户只能取得某旉点的数据 set transaction read only?br />12.sys用户和system用户区别
  1Q存储的数据的重要性不同?br />     sys:所有oracle的数据字典的和视N存放在sys用户中,q些和视囑֯于oracle的运行时臛_重要Q由数据库自q护,M用户都不能手动更攏Vsys用户拥有dbaQsysdbaQsysoper角色或权限,是oracle权限最高用戗?br />     systemQ用于存放次一U的内部数据Q如oracle的一些特性或工具的管理信息。system用户拥有dbaQsysdba角色或系l权限?br />  2Q权限的不同
     sys用户必须以as sysdba或assysoper形式dQ不能以normal方式d数据库?br />     system如果正常dQ它其实是一个普通的dba用户Q但是如果以as sysdbadQ其l果实际上它是作为sys用户d的?br />13.sysdba和sysoper权限区别
   pȝ权限        sysdba                                               sysoper
                       startupQ启动数据库Q?                         startup 
                       ShutdownQ关闭数据库Q?                     shutdown
                       alter database open/mount/backup     alter database open/mount/backup
                       改变字符?                                          不能
                       create database                                  不能创徏数据?/span>
    区别             drop database                                     不能删除数据?/span>
                       create spfile                                        create spfile
                       alter database archivelogQ归档日志)  alter database archivelog
                       alter database recover(恢复数据?      只能完全恢复,不能执行不完全恢?/span>
                       拥有 restricted sessionQ会话限Ӟ       拥有restricted session权限
                       可以让用户作为sys用户q接                    可以q行一些基本的操作Q?br />                                                                                 但不能查看用h?/span>
                       d之后用户是sys                                d之后用户public
14.逻辑备䆾
    逻辑备䆾是指使用工具export数据对象的l构和数据导出到文g的过E,逻辑恢复是指当数据库对象被误操作而损坏后使用工具import利用备䆾的文件把数据对象导入到数据库的过E。物理备份即可在数据库open的状态下q行也可在关闭数据库q行Q但是逻辑备䆾和恢复只能在open的状态下q行?br />15.oracle导出Q分为导Q导出方案,导出数据库方式?br />     导出使用exp命o来完成,该命令常用的选项有:
      useridQ用于指定执行导出操作的用户名,口oQ连接字W串Q?br />      tablesQ用于指定执行导出操作的表;
      ownerQ用于指定执行导出操作的ҎQ?br />      full=y:用于指定执行导出操作的数据库Q?br />      inctypeQ用于指定执行导出操作的增量cd
      rowsQ用于指定执行导出操作是否要导出表中的数据;rows=n只导的结?br />      fileQ用于指定导出文件名?br />16.导出?需要切换到oracle安装目录下的bin目录
   1Q导q?exp userid=scott/tiger@oracle tables=(emp) file=d:\e1.dmp
   2)导出其他Ҏ的表。如果用戯导出其他Ҏ的表Q则需要dba的权限或是exp_full_database的权限,比如system可以导出scott的表。exp userid=system/manager@oracle tables=(scott.emp) file=d:\e2.dmp
   3Q导的结?  exp userid=scott/tiger@oracle tables=(emp) file=d:\e3.dmp rows=n
   4)使用直接导出方式 exp userid=scott/tiger@oracle tables=(emp) file=d:\e3.dmp direct=yQ这U方式比默认的常规方式速度要快Q当数据量大Ӟ可以考虑使用q样的方式,q时需要数据库的字W集要与客户端字W集完全一_否则会报错?br />17.oracle导出ҎQ导出方案是指用export工具导出一个方案或是多个方案中的所有对象(表,索引Q约?..Q和数据。ƈ存到文g?br />  1Q导qҎ exp scott/tiger@oracle owner=scott file=d:\scott.dmp
  2)导出其他Ҏ 如果用户要导出其他方案,则需要dba的权限或是exp_full_database的权限,例如system用户可以导ZQ何方案?exp system/manager@oracle owner=(system,scott) file=d:\system.dmp?br />18.oracle导出数据?br />  1Q导出数据库是是指利用export导出所有数据库中的对象及数据,要求改用户具有dba的权限或是exp_full_database权限?exp userid=system/manager@oracle full=y inctype=complete file=x.dmp。注意:因ؓ数据量大Q所以好用的旉会较ѝ?br />19.导入Q导入就是用工具import文件中的对象和数据导入到数据库中,但是导入要用文件必Lexport所到处的文件。与导出怼Q导入也分ؓ导入表,导入ҎQ导入数据库三种方式?br />    useridQ用于指定执行导入操作的用户名,口oQ连接字W串Q?br />    tablesQ用于指定执行导入操作的表;
    fromuserQ用于指定源用户Q?br />    touserQ用于指定目标用P
    fileQ用于指定导入文件名Q?br />    full=y:用于指定执行导入整个文g
    inctypeQ用于指定执行导入操作的增量cd
    rowsQ指定是否到导入表行Q数据)
    ignoreQ如果表存在Q则只导入数?br />20.oracle导入?br />  1Q导入自p imp userid=scott/tiger@oracle tables=(emp) file=d:\e.dmp
  2Q导入表到其它用?要求该用户具有dba的权限,或是imp_full_database
        imp userid=system/manager@oracle tables=(emp) file=d:/e.dmp touser=scott
   3Q导入表的结构(只导入表的结构而不导入数据Q?br />        imp userid=scott/tiger@oracle tables=(emp) file=d:/e.dmp rows=n
   4Q导入数?如果对象Q如比表Q已l存在可以只导入表的数据
        imp userid=scott/tiger@oracle tables=(emp) file=d:\e.dmp ignore=y
21.oracle导入Ҏ
  1Q导入自w的Ҏ imp userid=scott/tiger file=d:\e.dmp
  2Q导入其它方案(要求该用户具有dba的权限或是imp_full_database权限Q?br />       imp userid=system/manager file=d:\e.dmp fromuser=system touser=scott
22.oracle导入数据库,在默认情况下Q当导入数据库时Q会导入所有对象结构和数据?br />    imp userid=system/manager@oracle full=y file=d:\e.dmp
23.数据字典和动态性能视图
  1Q数据字典是oracle数据库中最重要的组成部分,它提供了数据的一些系l信息;记录了数据的pȝ信息Q它是只读表和视囄集合Q数据字典的所有者ؓsys用户Q用户只能在数据字典上执行查询操作,而其l护和修改由pȝ自动完成?br />  2Q动态性能视图记蝲了例E启动后的相关信息?br />  3Q数据字典包括数据字典基表和数据字典视图Q其中基表存储数据库的基本信息,普通用户不能直接访问数据字典的Q数据字典视图是Z数据字典所建立的视图,普通用户可以通过查询数据字典视图取得pȝ信息。数据字典视图主要包括:user_xxx,all_xxx,dba_xxx三种cd?br />  4Quser_tablesQ用于显C当前用h拥有的所有表Q它只返回用h对应Ҏ的所有表。例如:select table_name from user_tables;
   5)all_tablesQ用于显C当前用户可以访问的所有表Q它不仅会返回当前用h案的所有表Q还会返回当前用户可以访问的其他Ҏ的表Q?br />   6Qdba_tablesQ它会显C所有方案拥有的数据库表Q但是查询这U数据库字典视图Q要求用户必Ldba角色或是有select_any_tablepȝ权限。例如:当用system用户查询数据字典视图dba_tablesӞ会返回system,sys,scott...Ҏ所对应的数据库表?br />24.oracle用户名,权限Q角?br />    在徏立用hQoracle会把用户的信息存攑ֈ数据字典中,当给用户授予权限或是角色Ӟoracle会将权限和角色的信息存放到数据字Dc通过查询
dba_users可以昄所有数据库用户的详l信息;通过查询数据字典视图dba_sys_privsQ可以显C用h拥有的系l权限;通过查询数据字典视图dba_tab_privs可以昄用户h的对象权限;通过查询数据字典视图dba_col_privs可以昄用户h的列权限Q通过查询数据字典视图dba_role_privs可以昄用户所h的角Ԍ通过查询所有的角色dba_rolesQ查询数据库的表I间dba_tablespacesQ简化权限的理?br />25.如何查询一个角Ԍ包括的权?br />    1Q一个角色包含的pȝ权限 select * from dba_sys_privs where grantee='CONNECT' 或?select * from role_sys_privs where role='CONNECT'
    2)一个角色包含的对象权限 select * from dba_tab_privs where grantee='CONNECT'
26.查询某个用户h怎样的角?br />    select * from dba_role_privs where grantee='用户?
27.昄当前用户可以讉K的所有数据字典视?br />     select * from dict where comments like '%grant%';
28.昄当前数据库的全称
     select * from global_name;
29.
查询该用h有哪些烦?/span>

  select index_name from user_indexes;

  查询该用h有哪些视?/p>

  select view_name from user_views;

  查询该用h有哪些数据库对象,对象包括表、视图、存储过E、触发器、包、烦引、序列、JAVA文g{?/p>

  select object_name from user_objects;

  主要描述当前用户的信息,主要包括当前用户名、帐户id、帐L态、表I间名、创建时间等?/p>

  select * from user_users;
30.数据字典分ؓ静态数据字典和动态数据字典?br />  1Q静态数据字典:主要是在用户讉K数据字典时不会发生改变的。主要由表和视图l成Q?br />  2Q动态数据字典:是依赖数据库q行的性能的,反映数据q行的一些内在信息。oracle中这些动态性能视图都是以v$开头的视图Q?br />  3Q?span style="font-size: 14px; line-height: 25px; ">v$access

  该视图显C数据库中锁定的数据库对象以及访问这些对象的会话对象Qsession对象Q?/p>

  select * from v$access

  v$session

  该视囑ֈ出当前会话的详细信息?/p>

  v$active_instance

  该视图主要描q当前数据库下的zd的实例的信息。依然可以用select语句来观察该信息?/p>

  v$context

  该视囑ֈ出当前会话的属性信息。比如命名空间、属性值等
31.oracle表空间和数据文g
   1Q表I间是数据库的逻辑l成部分。从物理上讲Q数据库数据存放在数据文件中Q从逻辑上讲Q数据库则存攑֜表空间中Q表I间׃个或多个数据文gl成?br />   2Qoracle中逻辑l构包括表空间、段、区、块。数据库pI间构成Q而表I间由段构成Q而段由区构成Q而区又是由oracle块构成,提高数据库的效率?br />   3Q表I间用于从逻辑上组l数据库的数据。数据库逻辑上是׃个或多个表空间组成。通过表空间可以达C下作用:控制数据库占有的盘I间Qdba可以不同数据类型部|到不同的位|,q样有利于提高I/O性能Q同时利于备份和恢复{管理操作?br />32.理表空间和数据文g
   1Q徏立表I间
     建立表空间是使用create tablespace命o完成Q需要注意是Q一般情况下Q徏立表I间是特权用h是dba来执行的Q如果用其他用户来创I间Q则用户必须要具有create tablespace 的系l权限?br />   2Q创建数据表I间
     在徏立数据库后,Z于管理表Q最好徏立自q表空?create tablespace data01 datafile 'd:\test\data01.dbf' size 20m uniform size 128k。在执行完命令后Q会建立名称为data01的表I间Qƈ表空间徏立名UCؓdata01.dbf的数据文Ӟ区的大小128k
    3Q用数据表I间
      create table mypart (deptno number(3),dname varchar2(14)) tablespace data01;
    4Q改变表I间的状?br />      当徏立表I间Ӟ表空间处于联机的QonlineQ状态,此时该表I间是可以访问的Qƈ且该表空间是可以d的。但是在q行pȝl护或是数据库维护时Q可能需要改变表I间的状态,一般由Ҏ用户或是dba来操作?br />    5Q表空间脱?alter tablespace users offline;
    6Q表空间联?alter tablespace users online;
    7Q只读表I间 当徏立表I间Ӟ表空间可以读写,如果不希望在该表I间上执行updateQdeleteQinsert操作Q那么可以将表空间修改ؓ只读 allter tablespace read only或?read write ?br />    8Q知道表I间名,昄该表I间包括的所有表 select * from all_tables where tablespace_name='表空间名'
    9Q知道表名,查看该表属于那个表空?select * from user_tables where table_name='emp'?br />    10Q删除表I间 
      drop tablespace '表空间名' including contents and datafiles;
      说明Qincluding contents表示删除表空间时Q删除该I间的所有数据库对象Q而datafiles 表示数据库文g也删除?br />33.oracle 扩展表空间的方式
   1Q增加数据文?alter tablespace data01 add datafile 'd:\test\data01.dbf' size 20m;
   2Q增减数据文件的大小 alter database datafile 'd:\test\data01.dbf' resize 20m;注意是数据文件的大小不要过500m;
   3Q设|文件的自动增长 alter database datafile 'd:\test\data01.dbf' autoextend on next 10m maxsize 500m;
34.oracleUd数据文g
    如果数据文g所在的盘损坏Ӟ该数据文件将不能再用,Z能够重新使用Q需要将q些文g的副本移动到其它的磁盘,然后恢复。下面以Ud数据文gsp01.dbfZ来说明:
   1Q确定数据文件所在的表空?select tablespace_name from dba_data_files where file_name='d:\test\sp01.dbf';
   2Q表空间脱?alter tablespace sp01 offline;
   3Q用命令移动数据文件到指定的目标位|?host move d:\test\sp01.dbf c:\test\sp01.dbf
   4Q执行alter tablespace 命o
     在物理上Ud了数据后Q还必须执行alter tablespace 命oҎ据库文gq行逻辑修改?alter tablespace sp02 rename datafile 'd:\test\sp01.dbf' to 'c:\test\sp01.dbf';
   5Q得表I间联机
     在移动了数据文g后,Z使用户可以访问该表空_必须其转变为online状?alter tablespace data01 online;
35.索引
   用于加速数据存取的数据对象。合理的使用索引可以大大降低I/Oơ数Q从而提高数据访问性能?br />36.昄角色信息
 1Q显C所有角色信?select * from dba_roles;
 2Q显C色所h的系l权?select * from role_sys_privs;
 3Q显C色具有的对象权限 select * from dba_tab_privs;
 4Q显C用户具有的角色及默认角艌Ӏ当以用Lw䆾q接到数据库Ӟoracle会自动的Ȁz默认的角色Q通过查询数据字典视图dba_role_privs可以昄某个用户h的所有角色及当前默认角色?br />37.oracle_讉K控制
  是指用户可以使用函数、策略实现更加细微的安全讉K控制。如果用精l访问控Ӟ则当在客L发出sql语句(select,insert,update,delete),oracle会自动在sql语句后追加谓?where 子句)Qƈ执行新的sql语句。通过q样的控Ӟ可以使得不同的数据库用户在访问相同表Ӟq回不同的数据信息?br />38.pl/sqlQprocedural language/sqlQ是oracle在标准的sql语言上的扩展。pl/sql不仅允许嵌入sql语言Q还可以定义变量和常量,允许使用条g语句和@环语句,允许使用例外处理各种错误Q这样得它的功能变得更加强大?br /> 1)作用。提高应用程序的q行性能Q模块化得设计思想Q减网l传输量Q提高安全性;不Q移植性不好;
39.执行单的pl/sql?br /> set serveroutput on -- 打开输出选项
 begin
    dbms_output.put_line('hello'); -- 是oracle所提供的包
 end;
40.pl/sqlCZ
 declare
    v_ename varchar2(5); -- 定义字符串变?br /> begin  
    select ename into v_ename from emp where empno=&no;
    dbms_output.put_line('');
 end;
  -- 表示要接收从控制台输入的变量
41.q程
  q程用于执行特定的操作,既可以制定输入参敎ͼ也可以制定输出参数。通过在过E中使用输入参数Q可以将数据传递到执行部分Q通过使用输出参数Q可以将执行部分的数据传递到应用环境。在sqlplus中可以用create procedure命o建立q程?br />42. 函数
  函数用于q回特定的数据,当徏立函数时Q在函数头部必须包含return 子句Q而在函数体内必须包含return语句q回的数据。create function来徏立函数?br />43. ?br /> 包用于在逻辑上组合过E和函数Q它由包规范和包体两部分l成?br /> 1Q可以?create package 命o来创建包?br />     create package sp_package is
            procedure update_sal(name varchar2,newsal number);
            function annual_income(name varchar2) return number;
     end;
 2Q徏立包体可以用create package body
44.触发?br /> 是指隐含的执行的存储q程。当定义触发器时Q必要指定触发的时间和触发的操作。常用的触发事g包括insertQupdateQdelete语句Q而触发操作实际就是一个pl/sql块。可以用create trigger来徏立触发器?/p>

kxbin 2012-08-06 20:56 发表评论
]]>
通过yum安装mysqlhttp://www.tkk7.com/kxbin/articles/383492.htmlkxbinkxbinThu, 19 Jul 2012 03:11:00 GMThttp://www.tkk7.com/kxbin/articles/383492.htmlhttp://www.tkk7.com/kxbin/comments/383492.htmlhttp://www.tkk7.com/kxbin/articles/383492.html#Feedback0http://www.tkk7.com/kxbin/comments/commentRss/383492.htmlhttp://www.tkk7.com/kxbin/services/trackbacks/383492.html1. 安装mysql

    1.1 执行安装

          $sudo yum -y install mysql-server

    1.2 注意

          mysql和mysql-server有区别,只需作ؓclientQ执行yum install mysql.

 

2. 服务和配|?/p>

    2.1 开机启?/p>

          $ sudo /sbin/chkconfig --add mysqld

          $ sudo /sbin/chkconfig mysqld on   

          $ sudo /sbin/service mysqld start

    2.2 讄root密码

          $sudo mysqladmin -u root password '1234'

 

3. q接mysql

    $mysql -h localhost -uroot -p1234

 



kxbin 2012-07-19 11:11 发表评论
]]>
linux下自动备份mysql数据?/title><link>http://www.tkk7.com/kxbin/articles/371783.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Tue, 13 Mar 2012 02:37:00 GMT</pubDate><guid>http://www.tkk7.com/kxbin/articles/371783.html</guid><wfw:comment>http://www.tkk7.com/kxbin/comments/371783.html</wfw:comment><comments>http://www.tkk7.com/kxbin/articles/371783.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/kxbin/comments/commentRss/371783.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/kxbin/services/trackbacks/371783.html</trackback:ping><description><![CDATA[1.创徏database.sh文gQ内容如下:<br />  #!/bin/sh<div>backupDate=`date +"%Y-%m-%d %H:%M:%S"`</div><div>mysqldump -uroot -proot tm>/test/database/tm$backupDate.sql<br />2.创徏d计划</div>  [root@localhost] crontab -e<br />  59 23 * * * /test/database/database.sh<img src ="http://www.tkk7.com/kxbin/aggbug/371783.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/kxbin/" target="_blank">kxbin</a> 2012-03-13 10:37 <a href="http://www.tkk7.com/kxbin/articles/371783.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mysql性能优化Q{Q?/title><link>http://www.tkk7.com/kxbin/articles/371649.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Sat, 10 Mar 2012 14:17:00 GMT</pubDate><guid>http://www.tkk7.com/kxbin/articles/371649.html</guid><wfw:comment>http://www.tkk7.com/kxbin/comments/371649.html</wfw:comment><comments>http://www.tkk7.com/kxbin/articles/371649.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/kxbin/comments/commentRss/371649.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/kxbin/services/trackbacks/371649.html</trackback:ping><description><![CDATA[<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">mysql> <span style="color: #0000ff; ">select * from abc_number_prop where number_id in (select number_id from abc_number_phone where phone = '82306839');</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="color: #ff0000; ">Z节省幅Q省略了输出内容Q下同?/span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">67 rows in set (12.00 sec)</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">只有67行数据返回,却花?2U,而系l中可能同时会有很多q样的查询,pȝ肯定扛不住。用desc看一?注:explain也可)</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">mysql> <span style="color: #0000ff; ">desc select * from abc_number_prop where number_id in (select number_id from abc_number_phone where phone = '82306839'); </span><br />+----+--------------------+------------------+--------+-----------------+-------+---------+------------+---------+--------------------------+<br />| id | select_type        | table            | type   | possible_keys   | key   | key_len | ref        | rows    | Extra                    |<br />+----+--------------------+------------------+--------+-----------------+-------+---------+------------+---------+--------------------------+<br />|  1 | PRIMARY            | abc_number_prop  | ALL    | NULL            | NULL  | NULL    | NULL       | <strong style="font-weight: bold; ">2679838</strong> | Using where              |<br />|  2 | DEPENDENT SUBQUERY | abc_number_phone | eq_ref | phone,number_id | phone | 70      | const,func |     <strong style="font-weight: bold; ">  1</strong> | Using where; Using index |<br />+----+--------------------+------------------+--------+-----------------+-------+---------+------------+---------+--------------------------+<br />2 rows in set (0.00 sec)</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">从上面的信息可以看出Q在执行此查询时会扫描两癑֤万行Q难道是没有创徏索引吗,看一?/p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">mysql> <span style="color: #0000ff; ">show index from abc_number_phone; </span><br />+------------------+------------+-------------+--------------+-----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />| Table            | Non_unique | Key_name    | Seq_in_index | Column_name     | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |<br />+------------------+------------+-------------+--------------+-----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />| abc_number_phone |          0 | PRIMARY     |            1 | number_phone_id | A         |       36879 |     NULL | NULL   |      | BTREE      |         |               |<br />| abc_number_phone |          0 | phone       |            1 | phone           | A         |       36879 |     NULL | NULL   |      | BTREE      |         |               |<br />| abc_number_phone |          0 | phone       |            2 | number_id       | A         |       36879 |     NULL | NULL   |      | BTREE      |         |               |<br /><strong style="font-weight: bold; ">| abc_number_phone |          1 | number_id   |            1 | number_id       | A         |       36879 |     NULL | NULL   |      | BTREE      |         |               |</strong> <br />| abc_number_phone |          1 | created_by  |            1 | created_by      | A         |       36879 |     NULL | NULL   |      | BTREE      |         |               |<br />| abc_number_phone |          1 | modified_by |            1 | modified_by     | A         |       36879 |     NULL | NULL   | YES  | BTREE      |         |               |<br />+------------------+------------+-------------+--------------+-----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />6 rows in set (0.06 sec)<br /><br />mysql> <span style="color: #0000ff; ">show index from abc_number_prop;</span> <br />+-----------------+------------+-------------+--------------+----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />| Table           | Non_unique | Key_name    | Seq_in_index | Column_name    | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |<br />+-----------------+------------+-------------+--------------+----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />| abc_number_prop |          0 | PRIMARY     |            1 | number_prop_id | A         |      311268 |     NULL | NULL   |      | BTREE      |         |               |<br /><strong style="font-weight: bold; ">| abc_number_prop |          1 | number_id   |            1 | number_id      | A         |      311268 |     NULL | NULL   |      | BTREE      |         |               |</strong> <br />| abc_number_prop |          1 | created_by  |            1 | created_by     | A         |      311268 |     NULL | NULL   |      | BTREE      |         |               |<br />| abc_number_prop |          1 | modified_by |            1 | modified_by    | A         |      311268 |     NULL | NULL   | YES  | BTREE      |         |               |<br />+-----------------+------------+-------------+--------------+----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />4 rows in set (0.15 sec)</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">从上面的输出可以看出Q这两张表在number_id字段上创Z索引的?/p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">看看子查询本w有没有问题?/p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">mysql> <span style="color: #0000ff; ">desc select number_id from abc_number_phone where phone = '82306839'; </span><br />+----+-------------+------------------+------+---------------+-------+---------+-------+------+--------------------------+<br />| id | select_type | table            | type | possible_keys | key   | key_len | ref   | rows | Extra                    |<br />+----+-------------+------------------+------+---------------+-------+---------+-------+------+--------------------------+<br />|  1 | SIMPLE      | abc_number_phone | ref  | phone         | phone | 66      | const | <strong style="font-weight: bold; ">   6</strong> | Using where; Using index |<br />+----+-------------+------------------+------+---------------+-------+---------+-------+------+--------------------------+<br />1 row in set (0.00 sec)</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">没有问题Q只需要扫描几行数据,索引起作用了。查询出来看?/p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">mysql> <span style="color: #0000ff; ">select number_id from abc_number_phone where phone = '82306839'; </span><br />+-----------+<br />| number_id |<br />+-----------+<br />|      8585 |<br />|     10720 |<br />|    148644 |<br />|    151307 |<br />|    170691 |<br />|    221897 |<br />+-----------+<br />6 rows in set (0.00 sec)</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">直接把子查询得到的数据放C面的查询?/p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">mysql> <span style="color: #0000ff; ">select * from abc_number_prop where number_id in (8585, 10720, 148644, 151307, 170691, 221897);</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">67 rows in set (0.03 sec)</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">速度也快Q看来MySQL在处理子查询的时候是不够好。我在MySQL 5.1.42 ?MySQL 5.5.19 都进行了试Q都有这个问题?/p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">搜烦了一下网l,发现很多人都遇到q这个问题:</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">参考资?Q用连接(JOINQ来代替子查?Sub-Queries) mysql优化pd记录<br />http://blog.csdn.net/hongsejiaozhu/article/details/1876181<br />参考资?Q网站开发日?14)-MYSQL子查询和嵌套查询优化<br />http://dodomail.iteye.com/blog/250199</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">Ҏ|上q些资料的徏议,改用join来试试?/p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; ">修改前:select * from abc_number_prop where number_id in (select number_id from abc_number_phone where phone = '82306839');</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; ">修改后:select a.* from abc_number_prop a inner join abc_number_phone b on a.number_id = b.number_id where phone = '82306839';</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">mysql> <span style="color: #0000ff; ">select a.* from abc_number_prop a inner join abc_number_phone b on a.number_id = b.number_id where phone = '82306839';</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">67 rows in set (0.00 sec)</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">效果不错Q查询所用时间几乎ؓ0。看一下MySQL是怎么执行q个查询?/p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">mysql> <span style="color: #0000ff; ">desc select a.* from abc_number_prop a inner join abc_number_phone b on a.number_id = b.number_id where phone = '82306839';</span> <br />+----+-------------+-------+------+-----------------+-----------+---------+-----------------+------+--------------------------+<br />| id | select_type | table | type | possible_keys   | key       | key_len | ref             | rows | Extra                    |<br />+----+-------------+-------+------+-----------------+-----------+---------+-----------------+------+--------------------------+<br />|  1 | SIMPLE      | b     | ref  | phone,number_id | phone     | 66      | const           |   <strong style="font-weight: bold; "> 6</strong> | Using where; Using index |<br />|  1 | SIMPLE      | a     | ref  | number_id       | number_id | 4       | eap.b.number_id |    <strong style="font-weight: bold; ">3 </strong>|                          |<br />+----+-------------+-------+------+-----------------+-----------+---------+-----------------+------+--------------------------+<br />2 rows in set (0.00 sec)</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; ">结Q当子查询速度慢时Q可用JOIN来改写一下该查询来进行优化?/strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">|上也有文章_使用JOIN语句的查询不一定L使用子查询的语句快?/p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">参考资?Q改变了对Mysql子查询的看法<br />http://hi.baidu.com/yzx110/blog/item/e694f536f92075360b55a92b.html</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">正好手头有本《高性能MySQL》,阅了一下,W?.4?#8220;MySQL查询优化器的限制”4.4.1节“兌子查?#8221;正好讲到q个问题?/p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">MySQL有时优化子查询很差,特别是在WHERE从句中的IN()子查询。像上面我碰到的情况Q其实我的想法是MySQL会把</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; ">select * from abc_number_prop where number_id in (select number_id from abc_number_phone where phone = '82306839');</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">变成下面的样?/p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">select * from abc_number_prop where number_id in (8585, 10720, 148644, 151307, 170691, 221897);</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">但不q的是,实际情况正好相反。MySQL试图让它和外面的表生联pL“帮助”优化查询Q它认ؓ下面的exists形式更有效率</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; ">select * from abc_number_prop where exists (select * from abc_number_phone where phone = '</strong><strong style="font-weight: bold; ">82306839'</strong> <strong style="font-weight: bold; ">and number_id = abc_number_prop.number_id);<br /></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">mysql> <span style="color: #0000ff; ">select * from abc_number_prop where exists (select * from abc_number_phone where phone = '82306839' and number_id = abc_number_prop.number_id);</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">67 rows in set (10.89 sec)</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; "><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">mysql> <span style="color: #0000ff; ">desc select * from abc_number_prop where exists (select * from abc_number_phone where phone = '82306839' and number_id = abc_number_prop.number_id); </span><br />+----+--------------------+------------------+--------+-----------------+-------+---------+-------------------------------------+---------+--------------------------+<br />| id | select_type        | table            | type   | possible_keys   | key   | key_len | ref                                 | rows    | Extra                    |<br />+----+--------------------+------------------+--------+-----------------+-------+---------+-------------------------------------+---------+--------------------------+<br />|  1 | PRIMARY            | abc_number_prop  | ALL    | NULL            | NULL  | NULL    | NULL                                |<strong style="font-weight: bold; ">2660707 </strong>| Using where              |<br />|  2 | DEPENDENT SUBQUERY | abc_number_phone | eq_ref | phone,number_id | phone | 70      | const,eap.abc_number_prop.number_id |       <strong style="font-weight: bold; ">1 </strong>| Using where; Using index |<br />+----+--------------------+------------------+--------+-----------------+-------+---------+-------------------------------------+---------+--------------------------+<br />2 rows in set (0.01 sec)</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">q种in子查询的形式Q在外部表(比如上面的abc_number_propQ数据量较大的时候效率是很差的。(如果对于较小的表Q不会造成显著地媄响)</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25px; text-align: left; background-color: #ffffff; ">文中说到<strong style="font-weight: bold; ">一U优化方式就是,手工in里面的子查询查询出来Q然后再D执行</strong> Q这在程序中是可行的?/p><img src ="http://www.tkk7.com/kxbin/aggbug/371649.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/kxbin/" target="_blank">kxbin</a> 2012-03-10 22:17 <a href="http://www.tkk7.com/kxbin/articles/371649.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linuxpȝ下MYSQL备䆾与恢?/title><link>http://www.tkk7.com/kxbin/articles/368352.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Wed, 11 Jan 2012 09:12:00 GMT</pubDate><guid>http://www.tkk7.com/kxbin/articles/368352.html</guid><wfw:comment>http://www.tkk7.com/kxbin/comments/368352.html</wfw:comment><comments>http://www.tkk7.com/kxbin/articles/368352.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/kxbin/comments/commentRss/368352.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/kxbin/services/trackbacks/368352.html</trackback:ping><description><![CDATA[<div><div>本文介绍了linux下如何备份与恢复mysql数据库?/div> <div></div> <div>数据库备份是非常重要的。如果定期做好备份,q样可以在发生pȝ崩溃时恢复数据到最后一ơ正常的状态,把损失减到最?/div> <div></div> <div>一、 用命令实现备?/div> <div></div> <div>MySQLl提供了一个mysqldump命oQ我们可以用它进行数据备份?/div> <div></div> <div>按提C入密码,q就把tm数据库所有的表结构和# mysqldump -u root -p tm > tm_050519.sql数据备䆾到tm_050519.sql了,因ؓ要总进行备份工作,如果数据量大会占用很大空_q时可以利用gzip压羃数据Q命令如下:</div> <div><pre># mysqldump -u root -p tm | gzip > tm_050519.sql.gz</pre></div> <div></div> <div>pȝ崩溃Q重建系l时Q可以这h复数据:</div> <div><pre># mysqldump -u root -p tm < tm_050519.sql</pre></div> <div></div> <div>从压~文件直接恢复:</div> <div><pre>#gzip < tm_050519.sql.gz | mysqldump -u root -p tm</pre></div> <div></div> <div>当然Q有很多MySQL工具提供更直观的备䆾恢复功能Q比如用phpMyAdmin很方便。但我认为,mysqldump是最基本、最通用的?/div> <div></div> <div>二、利用crontabQ系l每天定时备份mysql数据?/div> <div></div> <div>利用pȝcrontab来定时执行备份文Ӟ按日期对备䆾l果q行保存Q达到备份的目的?/div> <div></div> <div>1、创Z存备份文件的路径/var/backup/mysqlbak</div> <div><pre># mkdir -p /var/backup/mysqlbak</pre></div> <div></div> <div>2、创?usr/sbin/bakmysql文g</div> <div></div> <div>#vi /usr/sbin/bakmysql.sh</div> <div><pre>#!/bin/bash # mysql备䆾脚本 cd /var/backup/mysqlbak/ dateDIR=`date +"%y-%m-%d"` mkdir -p $dateDIR/data for i in `/usr/local/www/mysql/bin/mysql -uroot -plin31415926 -e "show databases" | grep -v "Database" | grep -v "information_schema"` do /usr/local/www/mysql/bin/mysqldump -uroot -plin31415926 $i | gzip > /var/backup/mysqlbak/$dateDIR/${i}_${dateDIR}.gz done</pre></div> <div></div> <div>3、修Ҏ件属性,使其可执?/div> <div><pre># chmod +x /usr/sbin/bakmysql</pre></div> <div></div> <div>4、修?etc/crontab</div> <div><pre># crontab -e 在下面添?01 3 * * * root /usr/sbin/bakmysql</pre></div></div><img src ="http://www.tkk7.com/kxbin/aggbug/368352.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/kxbin/" target="_blank">kxbin</a> 2012-01-11 17:12 <a href="http://www.tkk7.com/kxbin/articles/368352.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在linux下安装mysqlhttp://www.tkk7.com/kxbin/articles/368347.htmlkxbinkxbinWed, 11 Jan 2012 08:37:00 GMThttp://www.tkk7.com/kxbin/articles/368347.htmlhttp://www.tkk7.com/kxbin/comments/368347.htmlhttp://www.tkk7.com/kxbin/articles/368347.html#Feedback0http://www.tkk7.com/kxbin/comments/commentRss/368347.htmlhttp://www.tkk7.com/kxbin/services/trackbacks/368347.html

一.下蝲mysql-5.1.45.tar.gz
http://dev.mysql.com/downloads
或其它地方下?/p>

?dmysql用户及mysql用户l,q把mysql用户攑ֈmysql用户l中
useradd mysql
{与用下面两条命令:
groupadd mysql
useradd -g mysql mysql

?上传?usr/local/src下(方便理Q解压安?br />[root@localhost src]# tar -zxvf mysql-5.1.45.tar.gz
[root@localhost src]# cd mysql-5.1.45

1.~译
[root@localhost mysql-5.1.45]# ./configure --prefix=/usr/local/mysql --with-charset=gbk --with-collation=gbk_chinese_ci --with-extra-charsets=all --with-named-curses-libs=/usr/lib/libncurses.so.5
2.安装
[root@localhost mysql-5.1.45]# make && make install (q个旉比较?

3.mysql加入到系l变量path?br />?usr/local/mysql/bin 加入到path中,q样在shell里就可以q行mysql相关的命令?br />[root@localhost mysql-5.1.45]# vi /etc/profile
加入
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH

如果同时安装tomcat可以采用下面的方?br />export TOMCAT_HOME=/home/coomix/apache-tomcat-5.5.27
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:TOMCAT_HOME/bin:$PATH

[root@localhost mysql-5.1.45]# source /etc/profile 佉K|文件立即生?/p>

4.q入到mysql文g夹下Q初始化mysql表格Q安?mysql 默认数据?
[root@localhost mysql-5.1.45]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin docs include lib libexec mysql-test share sql-bench
[root@localhost mysql]# mysql_install_db --user=mysql

5.修改目录权限
[root@localhost mysql]# chown -R root:mysql .
[root@localhost mysql]# chown -R mysql var
[root@localhost mysql]# chgrp -R mysql .

6.修改配置Q将mysql加入pȝ服务Q?
[root@localhost mysql]# cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
[root@localhost mysql]# cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld

 

7.启动mysql
[root@localhost mysql]# service mysqld
Usage: /etc/init.d/mysqld {start|stop|restart|reload|force-reload|status} [ MySQL server options ]
[root@localhost mysql]# service mysqld start
Starting MySQL.                                            [定]
[root@localhost mysql]#

8.使用mysqlQ默认root用户是没有密码的
[root@localhost mysql]# cd bin
[root@localhost bin]# ./mysql -u root -p
Enter password: 直接按回?br />Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.45-log Source distribution

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

9.修改root密码
[root@localhost bin]# mysqladmin -u root password 'root'
[root@localhost bin]# mysqladmin -u root -h host_name password 'root'
mysqladmin: connect to server at 'host_name' failed
error: 'Unknown MySQL server host 'host_name' (1)'
Check that mysqld is running on host_name and that the port is 3306.
You can check this by doing 'telnet host_name 3306'
[root@localhost bin]# ./mysql -u root -p
Enter password: 输入root
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.01 sec)

mysql> use mysql;
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
23 rows in set (0.00 sec)

mysql> quit
Bye
[root@localhost bin]#


附:[root@localhost mysql]# mysql_install_db --user=mysql执行后的昄Q?br />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:

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

Alternatively you can run:
/usr/local/mysql/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 /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

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



kxbin 2012-01-11 16:37 发表评论
]]>
Linux下安装mysqlhttp://www.tkk7.com/kxbin/articles/368125.htmlkxbinkxbinMon, 09 Jan 2012 03:33:00 GMThttp://www.tkk7.com/kxbin/articles/368125.htmlhttp://www.tkk7.com/kxbin/comments/368125.htmlhttp://www.tkk7.com/kxbin/articles/368125.html#Feedback0http://www.tkk7.com/kxbin/comments/commentRss/368125.htmlhttp://www.tkk7.com/kxbin/services/trackbacks/368125.html# tar -zxvf mysql-5.0.45.tar.gz -C /usr/src/
# cd /usr/src/mysql-5.0.45
# ./configure --prefix=/usr/local/mysql --with-charset=gbk --localstatedir=/usr/local/mysql/data
# make
# make install
# groupadd mysql
# useradd mysql -g mysql
# cd /usr/local/mysql/bin
# ./mysql_install_db --user=mysql
# cd /usr/local/mysql
# chown -R root .
# chown -R mysql data
# chown -R mysql data/ .
# chown -R mysql data/mysql/ .
# chgrp -R mysql .
# /usr/local/mysql/bin/mysqld_safe --user=mysql &
# netstat -tnl |grep 3306
# /usr/local/mysql/bin/mysql -uroot -p
# show database;
# /usr/local/mysql/bin/mysqladmin -uroot password 6220104
# cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
# cd /etc/init.d/
# chmod +x mysqld
# chkconfig mysqld
# chkconfig --add mysqld
# chkconfig --level 345 mysqld on
# service mysqld stop
# cp /usr/local/mysql/bin/* /usr/bin/
到此mysql-5.0.45 安装完成Q?

kxbin 2012-01-09 11:33 发表评论
]]>
关于 No operations allowed after connection closed.错误http://www.tkk7.com/kxbin/articles/365775.htmlkxbinkxbinWed, 07 Dec 2011 08:24:00 GMThttp://www.tkk7.com/kxbin/articles/365775.htmlhttp://www.tkk7.com/kxbin/comments/365775.htmlhttp://www.tkk7.com/kxbin/articles/365775.html#Feedback0http://www.tkk7.com/kxbin/comments/commentRss/365775.htmlhttp://www.tkk7.com/kxbin/services/trackbacks/365775.html

ERROR - No operations allowed after connection closed.
2011-12-07 11:36:09 - ERROR - query failed
org.hibernate.exception.JDBCConnectionException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2148)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
分析Q出现这U异常的原因是:
Mysql服务器默认的“wait_timeout”?时Q也是说一个connectionI闲过8个小ӞMysql自动断开该connection。这是问题的所在,在C3P0 pools中的connections如果I闲过8时Qmysql其断开Q而C3P0q不知道该connection已经失效Q如果这时有ClienthconnectionQC3P0该失效的Connection提供lClientQ将会造成上面的异常?/div>
a)解决的方法有3U:
    增加wait_timeout的时间?/div>
    减少Connection pools中connection的lifetime?/div>
    试Connection pools中connection的有效性?/div>
b)具体解决ҎQ?br />   1、换一下JDBC驱动QJDBC3.1.0-alpha及以前版本会出现此问题,下蝲新的JDBC驱动
  2、用hibernate配置Q?/div>
使用hibernateQ?nbsp;
<property name="connection.autoReconnect">true</property>  <!--q个是最主要?-> 
<property name="connection.autoReconnectForPools">true</property> 
<property name="connection.is-connection-validation-required">true</property> 
加入以上propertyQ可解决此问题,如果未用hibernate{持久化理框架Q可在mysql的url中加入autoReconnect=trueQ这样就可以解决?/div>
原因很简单。在Ҏ据库操作l束后关闭连接是正确的做法,没什么大问题。至于出玎ͼNo operations allowed after connection closed。这L问题原因只有一个,你这里和数据库的q接Connection是一个Static的,E序׃nq一个Connection。所以第一ơ对数据库操作没问题Q当把Connection关闭后,W二ơ还x作数据库时Connection肯定不存在了?/div>


kxbin 2011-12-07 16:24 发表评论
]]>mysql恢复/备䆾命ohttp://www.tkk7.com/kxbin/articles/364683.htmlkxbinkxbinThu, 24 Nov 2011 00:05:00 GMThttp://www.tkk7.com/kxbin/articles/364683.htmlhttp://www.tkk7.com/kxbin/comments/364683.htmlhttp://www.tkk7.com/kxbin/articles/364683.html#Feedback0http://www.tkk7.com/kxbin/comments/commentRss/364683.htmlhttp://www.tkk7.com/kxbin/services/trackbacks/364683.html
1.备䆾命o
mysqldump -u root -p --default-character-set=utf8 itsm>itsm.sql 
2.恢复命o
mysql -uroot -p --default-character-set=utf8 itsm<e:\pole.sql


kxbin 2011-11-24 08:05 发表评论
]]>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 'cross ' at line 1 问题http://www.tkk7.com/kxbin/articles/364608.htmlkxbinkxbinWed, 23 Nov 2011 00:58:00 GMThttp://www.tkk7.com/kxbin/articles/364608.htmlhttp://www.tkk7.com/kxbin/comments/364608.htmlhttp://www.tkk7.com/kxbin/articles/364608.html#Feedback0http://www.tkk7.com/kxbin/comments/commentRss/364608.htmlhttp://www.tkk7.com/kxbin/services/trackbacks/364608.html阅读全文

kxbin 2011-11-23 08:58 发表评论
]]>
数据库的定时备䆾http://www.tkk7.com/kxbin/articles/360346.htmlkxbinkxbinMon, 10 Oct 2011 01:46:00 GMThttp://www.tkk7.com/kxbin/articles/360346.htmlhttp://www.tkk7.com/kxbin/comments/360346.htmlhttp://www.tkk7.com/kxbin/articles/360346.html#Feedback0http://www.tkk7.com/kxbin/comments/commentRss/360346.htmlhttp://www.tkk7.com/kxbin/services/trackbacks/360346.html
@echo off 
rem  ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
rem  ┣----------------------提示:-----------------------------------┫
rem  ┣--该批处理为数据库备䆾操作文g.-------------------------------┫
rem  ┣--׃sqlserver自带备䆾{略,无需使用批处?-------------------┫
rem  ┣--所以对应数据库cd仅包涵oracle,mysql两种.-------------------┫
rem  ┣--存放目录格式如d:\backup\crmnew------------------------------┫
rem  ┣--盘符下一Uؓȝ录的文g夹名 例如backup---------------------┫
rem  ┣--二Z用该数据库的目名称 例如crmnew---------------------┫
rem  ┣--执行环境为windows server 2003-------------------------------┫
rem  ┣--~写?CWCA-研发?刘洋-2011-7-25---------------------------┫
rem  ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
rem ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
rem   ----------------------初始讄?---------------------------
rem   讄目库备份文件存放根目录-脚本自动创徏
set   bak_dir=d:\databak
rem   讄目名称
set   project_name=cwcanew
rem   选择备䆾数据所使用的压~Y?/div>
set   compressFile=c:\uncompress\WinRAR\Rar.exe
rem   讄数据库的cd,仅支持oracle和mysql
set   db_type=oracle
rem   讄登陆目的数据库的标识,oracle为sid,mysql为库?/div>
set   db_name=oracle
rem   讄登陆目的数据库的用户?/div>
set   db_user=****
rem   讄登陆目的数据库的用户密码
set   db_pwd=****
rem   讄备䆾周期,1为按天备?7为按周备?/div>
set   bak_cycle=1
rem   讄每个备䆾文g的保留天??则表CZ删除历史文g
set   keep_days=0
rem ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
rem ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
rem   ----------------------可选设|项----------------------------
rem   获取当天为星期几
set   pweek=%date:~-1%
rem   讄单个备䆾文g?此处?目名称_日期"命名-?crmnew_20110101 -不要更改
set   filename=%project_name%_%Date:~0,4%q?Date:~5,2%?Date:~8,2%?/div>
rem ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
rem ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
rem   ----------------------------------------执行代码区域----------------------------------------
if not exist %bak_dir%\%project_name% mkdir %bak_dir%\%project_name%
set   bakfile=%bak_dir%\%project_name%\%filename%
set   filesuffix=
      if %db_type% equ oracle set filesuffix=dmp
      if %db_type% equ mysql set filesuffix=sql
      if %bak_cycle% equ 7 (
       if %pweek% equ ?goto backup
       goto end
      ) 
      if %bak_cycle% equ 1 goto backup
      goto end
      :backup
      if %db_type% equ oracle goto backup_oracle
      if %db_type% equ mysql goto backup_mysql
      goto end
      :backup_oracle
      exp %db_user%/%db_pwd%@%db_name% file=%bakfile%.%filesuffix%
      goto compress
      :backup_mysql
      mysqldump -u%db_user% -p%db_pwd% %db_name% > %bakfile%.%filesuffix%
      goto compress
      :compress
      %compressFile% a %bakfile%.rar %bakfile%.%filesuffix%
      goto delete_source
      :delete_source
      del %bakfile%.%filesuffix%
      goto delete_history
      :delete_history
      if %keep_days% neq 0 forfiles /p %bak_dir%\%project_name%\ /d -%keep_days% /c "cmd /c echo deleting @file ... && del /f @path"
      goto end
      :end
set   bak_dir=
set   project_name=
set   compressFile=
set   db_type=
set   db_name=
set   db_user=
set   db_pwd=
set   bak_cycle=
set   keep_days=
set   pweek=
set   filename=
set   bakfile=
set   filesuffix=
rem ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
pause


kxbin 2011-10-10 09:46 发表评论
]]>试数据库的默认最大连接数http://www.tkk7.com/kxbin/articles/358775.htmlkxbinkxbinFri, 16 Sep 2011 03:00:00 GMThttp://www.tkk7.com/kxbin/articles/358775.htmlhttp://www.tkk7.com/kxbin/comments/358775.htmlhttp://www.tkk7.com/kxbin/articles/358775.html#Feedback0http://www.tkk7.com/kxbin/comments/commentRss/358775.htmlhttp://www.tkk7.com/kxbin/services/trackbacks/358775.html
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
 * 试的最大连接数
 * oracle的默认连接数?35
 * Mysql的默认连接数?00
 * @author kxbin
 * 
 */
class testMaxConn {
int count = 0; // q接?/div>
Connection[] conn = new Connection[1000];
Statement[] stmt = new Statement[1000];
ResultSet[] rs = new ResultSet[1000];
/**
* 数据库连接方法(oracleQ?/div>
*/
public void testOracleMaxConn() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@localhost:1521:compare";
for (count = 0; count < 135; count++) {
conn[count] = DriverManager.getConnection(url,"nxcompare", "64compare");
stmt[count] = conn[count].createStatement();
rs[count] = stmt[count].executeQuery("SELECT * FROM users");
System.out.print(count + "\t");
}
} catch (SQLException ex1) {
System.out.println("\n" + ex1.toString());
} catch (InstantiationException ex2) {
System.out.println("\n" + ex2.toString());
} catch (ClassNotFoundException ex3) {
System.out.println("\n" + ex3.toString());
} catch (IllegalAccessException ex4) {
System.out.println("\n" + ex4.toString());
} finally {
try {
System.out.println("\npȝ打开的连接数"+ count--+ " oracle connections.\nh回R按钮Q进行关?);
System.in.read();
System.out.println("\n闭关q接:");
for (; count >= 0; count--) {
rs[count].close();
stmt[count].close();
conn[count].close();
System.out.print(count + "\t");
}
} catch (SQLException ex) {
System.out.println("\n 关闭q接出现SQLExceptionQ?+ ex.toString());
} catch (IOException io_ex) {
System.out.println("\n 关闭q接出现IOExceptionQ?+ io_ex.toString());
}
}
}
/**
* 数据库连接方法(MysqlQ?/div>
*/
public void testMysqlMaxConn() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/tm?useUnicode=true&characterEncoding=GBK";
for (count = 0; count < 100; count++) {
conn[count] = DriverManager.getConnection(url,"root", "root");
stmt[count] = conn[count].createStatement();
rs[count] = stmt[count].executeQuery("SELECT * FROM userinfo");
System.out.print(count + "\t");
}
} catch (SQLException ex1) {
System.out.println("\n" + ex1.toString());
} catch (InstantiationException ex2) {
System.out.println("\n" + ex2.toString());
} catch (ClassNotFoundException ex3) {
System.out.println("\n" + ex3.toString());
} catch (IllegalAccessException ex4) {
System.out.println("\n" + ex4.toString());
} finally {
try {
System.out.println("\npȝ打开的连接数"+ count--+ " MYSQL connections.\nh回R按钮Q进行关?);
System.in.read();
System.out.println("\n闭关q接:");
for (; count >= 0; count--) {
rs[count].close();
stmt[count].close();
conn[count].close();
System.out.print(count + "\t");
}
} catch (SQLException ex) {
System.out.println("\n 关闭q接出现SQLExceptionQ?+ ex.toString());
} catch (IOException io_ex) {
System.out.println("\n 关闭q接出现IOExceptionQ?+ io_ex.toString());
}
}
}
/**
* 试Ҏ
* @param args
* @throws Exception
*/
public static void main(String args[]) throws Exception {
// new testMaxConn().testOracleMaxConn(); //试Oracle默认最大连接数135
new testMaxConn().testMysqlMaxConn(); //试MYSQLQ默认最大连接数100
}
}


kxbin 2011-09-16 11:00 发表评论
]]>mysql中文q解决Ҏhttp://www.tkk7.com/kxbin/articles/358626.htmlkxbinkxbinWed, 14 Sep 2011 08:30:00 GMThttp://www.tkk7.com/kxbin/articles/358626.htmlhttp://www.tkk7.com/kxbin/comments/358626.htmlhttp://www.tkk7.com/kxbin/articles/358626.html#Feedback0http://www.tkk7.com/kxbin/comments/commentRss/358626.htmlhttp://www.tkk7.com/kxbin/services/trackbacks/358626.html
q问题解决
my.ini中的default-character-set = gb2312 
然后 String url = "jdbc:mysql://localhost:3306/LibraryManagementSystem?useUnicode=true&characterEncoding=GB2312"; 
在hibernate的ؕ码问?/div>
<property name="connection.url">
   jdbc:mysql://localhost:3306/hibernate?useUnicode=true&amp;characterEncoding=UTF-8
</property>


kxbin 2011-09-14 16:30 发表评论
]]>
批处理执行创I间和表MYSQLhttp://www.tkk7.com/kxbin/articles/358624.htmlkxbinkxbinWed, 14 Sep 2011 08:25:00 GMThttp://www.tkk7.com/kxbin/articles/358624.htmlhttp://www.tkk7.com/kxbin/comments/358624.htmlhttp://www.tkk7.com/kxbin/articles/358624.html#Feedback0http://www.tkk7.com/kxbin/comments/commentRss/358624.htmlhttp://www.tkk7.com/kxbin/services/trackbacks/358624.html1。徏立一个bat文gQ内容如下:
@echo off
"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql.exe" -h localhost --user=root --password=root --port=3306 mysql < tm.sql > d:/tm.log
echo 数据库和表创建成功,d的初始用户名:adminQ密?admin;用户cd为:理?/div>
echo hL键退?..........!
pause>nul
2。徏立一个sql文gQ内容如下: 
-- 如果已经存在数据库,则删?/div>
DROP database IF EXISTS `tm`;
create   database   tm   default   character   set   gbk;
USE tm;
set names gbk; 
-- 1 用户账号理 ==============================================================
create table userInfo 
(
   id                   int                            not null,
   userName             varchar(20), -- 用户?/div>
   password             varchar(20), -- 密码
   level                varchar(10), -- U别
   remark               varchar(100), -- 备注
   createDate           datetime,   -- 创徏旉
   deleteFlag           varchar(1), -- 是否删除(Y删除,N正常)
   constraint PK_USERINFO primary key clustered (id)
);
-- 默认d一个用?/div>
insert into userInfo values(1,'admin','admin','理?,'',now(),'N');


kxbin 2011-09-14 16:25 发表评论
]]> վ֩ģ壺 һĿ| 91Ʒѹۿ| ɫͼ߹ۿ| Ʒ㽶߹ۿ| ۺһպ| wwwƵ| ѾƷԲ߹ۿ| ˳WWW| ѹƵȫվ| ޹߾Ʒһ| պһƵ| һ˿hdƵ| Ƶһ| Ƶ| ԻAVƬѲŲ| þþþav| ߹ۿӾѰ | Avۺɫרɫ | ѿĻɫƬ| ˳Ƶ| վѹۿ| Ļѵַ߹ۿ| йڶѲ| ޹Ů߹ۿ| vvaþ| þĻƵ| ޾Һһ| þþþŷղAV| ŮȸͰƵѰ| þWWW˳ɡƬ| ݺɫۺվɫ | ۺɫ| ޾Ʒ뼤AV| 99Ʒ| ߿Ƭ˳Ƶ| xxxձ18| Ʒ߳| ԲƵ | ձһ߲Ͷ߲Ա| ҹҹ۲ӰԺ| Ұ¾þø|