create table `award_chance_history` ( `id` int(11) not null auto_increment, `awardactid` int(11) default null comment '活动id', `vvid` bigint(20) default null comment '用户id', `createtime` timestamp not null default current_timestamp on update current_timestamp comment '签到时间', `reason` varchar(40) default null comment '事由', `additionalchance` int(11) default '0' comment '积分变动', `type` int(11) default null comment '类型', `chance_bak` int(11) default '0', primary key (`id`) ) engine=innodb auto_increment=1 default charset=utf8; |
create table nums(id int not null primary key); delimiter $$ create procedure pcreatenums(cnt int) begin declare s int default 1; truncate table nums; while s<=cnt do insert into nums select s; set s=s 1; end while; end $$ delimiter ; delimiter $$ create procedure pfastcreatenums(cnt int) begin declare s int default 1; truncate table nums; insert into nums select s; while s*2<=cnt do insert into nums select id s from nums; set s=s*2; end while; end $$ delimiter ; |
[queue indatabase:^(fmdatabase *db) { [db executeupdate:@"insert into mytable values (?)", [nsnumber numberwithint:1]]; [db executeupdate:@"insert into mytable values (?)", [nsnumber numberwithint:2]]; fmresultset *rs = [db executequery:@"select * from foo"]; while([rs next]) { … } }]; |
[queue intransaction:^(fmdatabase *db, bool *rollback) { [db executeupdate:@"insert into mytable values (?)", [nsnumber numberwithint:1]]; [db executeupdate:@"insert into mytable values (?)", [nsnumber numberwithint:2]]; [db executeupdate:@"insert into mytable values (?)", [nsnumber numberwithint:3]]; if (somethingwronghappened) { *rollback = yes; return; } // etc… [db executeupdate:@"insert into mytable values (?)", [nsnumber numberwithint:4]]; }]; |
sql> select * from v$version; banner -------------------------------------------------------------------------------- oracle database 11g enterprise edition release 11.2.0.4.0 - 64bit production pl/sql release 11.2.0.4.0 - production core 11.2.0.4.0 production tns for 64-bit : version 11.2.0.4.0 - production nlsrtl version 11.2.0.4.0 – production |
sql> create table prim (v_id number(3), v_name varchar2(100)); table created sql> alter table prim add constraint pk_prim primary key (v_id); table altered sql> create table child (c_id number(3), v_id number(3), c_name varchar2(100)); table created sql> alter table child add constraint pk_child primary key (c_id); table altered |
sql> delete prim where v_id=2; 1 row deleted sql> select * from prim; v_id v_name ---- -------------------------------------------------------------------------------- 1 kk 3 iowkd sql> select * from child; c_id v_id c_name ---- ---- -------------------------------------------------------------------------------- 1 1 kll 2 1 ddkll 3 1 43kll sql> rollback; rollback complete |
sql> delete prim where v_id=2; 1 row deleted sql> select * from prim; v_id v_name ---- -------------------------------------------------------------------------------- 1 kk 3 iowkd sql> select * from child; c_id v_id c_name ---- ---- -------------------------------------------------------------------------------- 1 1 kll 2 1 ddkll 3 1 43kll 4 43kll 5 4ll sql> rollback; rollback complete |
sql> desc child; name type nullable default comments ------ ------------- -------- ------- -------- c_id number(3) v_id number(3) y c_name varchar2(100) y sql> alter table child modify v_id not null; table altered sql> desc child; name type nullable default comments ------ ------------- -------- ------- -------- c_id number(3) v_id number(3) c_name varchar2(100) y sql> delete prim where v_id=2; delete prim where v_id=2 ora-01407: 无法更新 ("a"."child"."v_id")为 null |
c:\users\华荣>sqlplus lhr/lhr@orclasm sql*plus: release 11.2.0.1.0 production on 星期三 11月 12 10:52:29 2014 凯发天生赢家一触即发官网 copyright (c) 1982, 2010, oracle. all rights reserved. 连接到: oracle database 11g enterprise edition release 11.2.0.3.0 - 64bit production with the partitioning, automatic storage management, olap, data mining and real application testing options sql> sql> sql> drop table t purge; 表已删除。 sql> create table t nologging as select * from dba_objects d ; 表已创建。 sql> create index ind_objectname on t(object_name); 索引已创建。 |
sql> desc t name null? type ----------------------------------------- -------- ---------------------------- owner varchar2(30) object_name varchar2(128) subobject_name varchar2(30) object_id number data_object_id number object_type varchar2(19) created date last_ddl_time date timestamp varchar2(19) status varchar2(7) temporary varchar2(1) generated varchar2(1) secondary varchar2(1) namespace number edition_name varchar2(30) sql> sql> set autotrace traceonly; sql> select t.object_name from t where t.object_name ='t'; 执行计划 ---------------------------------------------------------- plan hash value: 4280870634 ----------------------------------------------------------------------------------- | id | operation | name | rows | bytes | cost (%cpu)| time | ----------------------------------------------------------------------------------- | 0 | select statement | | 1 | 66 | 3 (0)| 00:00:01 | |* 1 | index range scan| ind_objectname | 1 | 66 | 3 (0)| 00:00:01 | ----------------------------------------------------------------------------------- predicate information (identified by operation id): --------------------------------------------------- 1 - access("t"."object_name"='t') note ----- - dynamic sampling used for this statement (level=2) - sql plan baseline "sql_plan_503ygb00mbj6k165e82cd" used for this statement 统计信息 ---------------------------------------------------------- 34 recursive calls 43 db block gets 127 consistent gets 398 physical reads 15476 redo size 349 bytes sent via sql*net to client 359 bytes received via sql*net from client 2 sql*net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed sql> select t.object_name from t where upper(t.object_name) ='t'; 执行计划 ---------------------------------------------------------- plan hash value: 1601196873 -------------------------------------------------------------------------- | id | operation | name | rows | bytes | cost (%cpu)| time | -------------------------------------------------------------------------- | 0 | select statement | | 12 | 792 | 305 (1)| 00:00:04 | |* 1 | table access full| t | 12 | 792 | 305 (1)| 00:00:04 | -------------------------------------------------------------------------- predicate information (identified by operation id): --------------------------------------------------- 1 - filter(upper("t"."object_name")='t') note ----- - dynamic sampling used for this statement (level=2) - sql plan baseline "sql_plan_9p76pys5gdb2b94ecae5c" used for this statement 统计信息 ---------------------------------------------------------- 29 recursive calls 43 db block gets 1209 consistent gets 1092 physical reads 15484 redo size 349 bytes sent via sql*net to client 359 bytes received via sql*net from client 2 sql*net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed sql> select t.object_name from t where upper(t.object_name) ='t' and t.object_name is not null ; 执行计划 ---------------------------------------------------------- plan hash value: 3379870158 --------------------------------------------------------------------------------------- | id | operation | name | rows | bytes | cost (%cpu)| time | --------------------------------------------------------------------------------------- | 0 | select statement | | 51 | 3366 | 110 (1)| 00:00:02 | |* 1 | index fast full scan| ind_objectname | 51 | 3366 | 110 (1)| 00:00:02 | --------------------------------------------------------------------------------------- predicate information (identified by operation id): --------------------------------------------------- 1 - filter("t"."object_name" is not null and upper("t"."object_name")='t') note ----- - dynamic sampling used for this statement (level=2) - sql plan baseline "sql_plan_czkarb71kthws18b0c28f" used for this statement 统计信息 ---------------------------------------------------------- 29 recursive calls 43 db block gets 505 consistent gets 384 physical reads 15612 redo size 349 bytes sent via sql*net to client 359 bytes received via sql*net from client 2 sql*net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed sql> select t.object_name,t.owner from t where upper(t.object_name) ||'aaa' ='t'||'aaa' and t.object_name is not null ; 执行计划 ---------------------------------------------------------- plan hash value: 1601196873 -------------------------------------------------------------------------- | id | operation | name | rows | bytes | cost (%cpu)| time | -------------------------------------------------------------------------- | 0 | select statement | | 51 | 4233 | 304 (1)| 00:00:04 | |* 1 | table access full| t | 51 | 4233 | 304 (1)| 00:00:04 | -------------------------------------------------------------------------- predicate information (identified by operation id): --------------------------------------------------- 1 - filter("t"."object_name" is not null and upper("t"."object_name")||'aaa'='taaa') note ----- - dynamic sampling used for this statement (level=2) - sql plan baseline "sql_plan_au9a1c4hwdtb894ecae5c" used for this statement 统计信息 ---------------------------------------------------------- 30 recursive calls 44 db block gets 1210 consistent gets 1091 physical reads 15748 redo size 408 bytes sent via sql*net to client 359 bytes received via sql*net from client 2 sql*net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed sql> select t.object_name from t where upper(t.object_name) ||'aaa' ='t'||'aaa' and t.object_name is not null ; 执行计划 ---------------------------------------------------------- plan hash value: 3379870158 --------------------------------------------------------------------------------------- | id | operation | name | rows | bytes | cost (%cpu)| time | --------------------------------------------------------------------------------------- | 0 | select statement | | 51 | 3366 | 110 (1)| 00:00:02 | |* 1 | index fast full scan| ind_objectname | 51 | 3366 | 110 (1)| 00:00:02 | --------------------------------------------------------------------------------------- predicate information (identified by operation id): --------------------------------------------------- 1 - filter("t"."object_name" is not null and upper("t"."object_name")||'aaa'='taaa') note ----- - dynamic sampling used for this statement (level=2) - sql plan baseline "sql_plan_1gu36rnh3s2a318b0c28f" used for this statement 统计信息 ---------------------------------------------------------- 28 recursive calls 44 db block gets 505 consistent gets 6 physical reads 15544 redo size 349 bytes sent via sql*net to client 359 bytes received via sql*net from client 2 sql*net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed sql> |
mysql> select current_timestamp; --------------------- | current_timestamp | --------------------- | 2014-11-26 17:51:27 | --------------------- 1 row in set (0.01 sec) mysql> show databases; //尚未创建数据库bkt -------------------- | database | -------------------- | information_schema | | john | | mysql | | performance_schema | -------------------- 4 rows in set (0.03 sec) mysql> ctrl-c -- aborted [root@mysql02 data]# mysql -uroot -p enter password: welcome to the mysql monitor. commands end with ; or \\g. your mysql connection id is 2 server version: 5.5.36-log source distribution 凯发天生赢家一触即发官网 copyright (c) 2000, 2014, 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 master status; ------------------ ---------- -------------- ------------------ | file | position | binlog_do_db | binlog_ignore_db | ------------------ ---------- -------------- ------------------ | mysql-bin.000001 | 107 | | | //当前数据库log的pos状态 ------------------ ---------- -------------- ------------------ 1 row in set (0.00 sec) mysql> select current_timestamp; //当前的时间戳 当前时间点a --------------------- | current_timestamp | --------------------- | 2014-11-26 17:54:12 | --------------------- 1 row in set (0.00 sec) mysql> create database bkt; //创建数据库bkt query ok, 1 row affected (0.01 sec) mysql> create table john (id varchar(32)); error 1046 (3d000): no database selected mysql> use bkt; error 1049 (42000): unknown database \'bkt\' mysql> use bkt; database changed mysql> create table john (id varchar(32)); query ok, 0 rows affected (0.02 sec) mysql> insert into john values(\'1\'); query ok, 1 row affected (0.01 sec) mysql> insert into john values(\'2\'); query ok, 1 row affected (0.01 sec) mysql> insert into john values(\'3\'); query ok, 1 row affected (0.00 sec) mysql> insert into john values(\'4\'); query ok, 1 row affected (0.01 sec) mysql> insert into john values(\'5\'); query ok, 1 row affected (0.01 sec) mysql> select current_timestamp; //插入5条数据后数据库的时间点b,记录该点便于数据库的恢复 --------------------- | current_timestamp | --------------------- | 2014-11-26 17:55:53 | --------------------- 1 row in set (0.00 sec) mysql> show master status; ------------------ ---------- -------------- ------------------ | file | position | binlog_do_db | binlog_ignore_db | ------------------ ---------- -------------- ------------------ | mysql-bin.000001 | 1204 | | | //当前binlog的pos位置 ------------------ ---------- -------------- ------------------ 1 row in set (0.00 sec) |
mysql> insert into john values(\'6\'); query ok, 1 row affected (0.02 sec) mysql> insert into john values(\'7\'); query ok, 1 row affected (0.01 sec) mysql> insert into john values(\'8\'); query ok, 1 row affected (0.01 sec) mysql> insert into john values(\'9\'); query ok, 1 row affected (0.01 sec) mysql> insert into john values(\'10\'); query ok, 1 row affected (0.03 sec) mysql> show master status; ------------------ ---------- -------------- ------------------ | file | position | binlog_do_db | binlog_ignore_db | ------------------ ---------- -------------- ------------------ | mysql-bin.000001 | 2125 | | | ------------------ ---------- -------------- ------------------ 1 row in set (0.00 sec) mysql> select current_timestamp; --------------------- | current_timestamp | --------------------- | 2014-11-26 17:58:08 | --------------------- 1 row in set (0.00 sec) |
[root@mysql02 data]# mysqlbackup --defaults-file=/backup/server-my.cnf --datadir=/data/mysql --backup-dir=/backup/ copy-back mysql enterprise backup version 3.11.0 linux-3.8.13-16.2.1.el6uek.x86_64-x86_64 [2014/08/26] 凯发天生赢家一触即发官网 copyright (c) 2003, 2014, oracle and/or its affiliates. all rights reserved. mysqlbackup: info: starting with following command line ... mysqlbackup --defaults-file=/backup/server-my.cnf --datadir=/data/mysql --backup-dir=/backup/ copy-back mysqlbackup: info: important: please check that mysqlbackup run completes successfully. at the end of a successful \'copy-back\' run mysqlbackup prints \"mysqlbackup completed ok!\". 141126 17:59:58 mysqlbackup: info: meb logfile created at /backup/meta/meb_2014-11-26.17-59-58_copy_back.log -------------------------------------------------------------------- server repository options: -------------------------------------------------------------------- datadir = /data/mysql innodb_data_home_dir = /data/mysql innodb_data_file_path = ibdata1:10m:autoextend innodb_log_group_home_dir = /data/mysql/ innodb_log_files_in_group = 2 innodb_log_file_size = 5242880 innodb_page_size = null innodb_checksum_algorithm = none -------------------------------------------------------------------- backup config options: -------------------------------------------------------------------- datadir = /backup/datadir innodb_data_home_dir = /backup/datadir innodb_data_file_path = ibdata1:10m:autoextend innodb_log_group_home_dir = /backup/datadir innodb_log_files_in_group = 2 innodb_log_file_size = 5242880 innodb_page_size = 16384 innodb_checksum_algorithm = none mysqlbackup: info: creating 14 buffers each of size 16777216. 141126 17:59:58 mysqlbackup: info: copy-back operation starts with following threads 1 read-threads 1 write-threads mysqlbackup: info: could not find binlog index file. if this is online backup then server may not have started with --log-bin. hence, binlogs will not be copied for this backup. point-in-time-recovery will not be possible. 141126 17:59:58 mysqlbackup: info: copying /backup/datadir/ibdata1. mysqlbackup: progress in mb: 200 400 600 141126 18:00:22 mysqlbackup: info: copying the database directory \'john\' 141126 18:00:23 mysqlbackup: info: copying the database directory \'mysql\' 141126 18:00:23 mysqlbackup: info: copying the database directory \'performance_schema\' 141126 18:00:23 mysqlbackup: info: completing the copy of all non-innodb files. 141126 18:00:23 mysqlbackup: info: copying the log file \'ib_logfile0\' 141126 18:00:23 mysqlbackup: info: copying the log file \'ib_logfile1\' 141126 18:00:24 mysqlbackup: info: creating server config files server-my.cnf and server-all.cnf in /data/mysql 141126 18:00:24 mysqlbackup: info: copy-back operation completed successfully. 141126 18:00:24 mysqlbackup: info: finished copying backup files to \'/data/mysql\' mysqlbackup completed //数据库恢复完成 |
-rwxrwxrwx. 1 root root 305 11月 26 18:00 backup_variables.txt -rwxrwxrwx. 1 root root 740294656 11月 26 18:00 ibdata1 -rwxrwxrwx. 1 root root 5242880 11月 26 18:00 ib_logfile0 -rwxrwxrwx. 1 root root 5242880 11月 26 18:00 ib_logfile1 drwxrwxrwx. 2 root root 4096 11月 26 18:00 john drwxrwxrwx. 2 root root 4096 11月 26 18:00 mysql drwxrwxrwx. 2 root root 4096 11月 26 18:00 performance_schema -rwxrwxrwx. 1 root root 8488 11月 26 18:00 server-all.cnf -rwxrwxrwx. 1 root root 1815 11月 26 18:00 server-my.cnf //没有bkt数据库 [root@mysql02 mysql]# service mysqld start //启动数据库 |
enter password: [root@mysql02 mysql2]# mysql -uroot -p enter password: welcome to the mysql monitor. commands end with ; or \\g. your mysql connection id is 3 server version: 5.5.36-log source distribution 凯发天生赢家一触即发官网 copyright (c) 2000, 2014, 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 | | bkt | | john | | mysql | | performance_schema | -------------------- 5 rows in set (0.02 sec) mysql> use bkt database changed mysql> show tables; --------------- | tables_in_bkt | --------------- | john | --------------- 1 row in set (0.00 sec) mysql> select * from john; ------ | id | ------ | 1 | | 2 | | 3 | | 4 | | 5 | ------ 5 rows in set (0.01 sec) //查看数据库恢复成功 |
[root@mysql02 mysql2]# mysqlbinlog --start-date=\"2014-11-27 09:21:56\" --stop-date=\"2014-11-27 09:22:33\" mysql-bin.000001| mysql -uroot -p123456 //本次通过基于时间点的恢复,恢复到时间点c warning: using unique option prefix start-date instead of start-datetime is deprecated and will be removed in a future release. please use the full name instead. warning: using unique option prefix stop-date instead of stop-datetime is deprecated and will be removed in a future release. please use the full name instead. [root@mysql02 mysql2]# mysql -uroot -p enter password: welcome to the mysql monitor. commands end with ; or \\g. your mysql connection id is 6 server version: 5.5.36-log source distribution 凯发天生赢家一触即发官网 copyright (c) 2000, 2014, 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 | | bkt | | john | | mysql | | performance_schema | -------------------- 5 rows in set (0.00 sec) mysql> use bkt database changed mysql> select * from john; ------ | id | ------ | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | | 10 | ------ 10 rows in set (0.00 sec) //经过检查成功恢复到时间点c |
sql> select * from v$version; banner -------------------------------------------------------------------------------- database 11g enterprise edition release 11.2.0.4.0 - 64bit production pl/sql release 11.2.0.4.0 - production core 11.2.0.4.0 production tns for 64-bit : version 11.2.0.4.0 - production nlsrtl version 11.2.0.4.0 – production 创建对应schema和数据表。 sql> create user a identified by a; user created sql> create user b identified by b; user created sql> grant connect, resource to a,b; grant succeeded sql> grant create procedure to a,b; grant succeeded sql> grant create synonym to a,b; grant succeeded |
sql> conn a/a@sicsdb connected to oracle database 11g enterprise edition release 11.2.0.4.0 connected as a sql> create table a(col varchar2(10)); table created sql> create or replace procedure proc(i_vc_name varchar2) is 2 begin 3 insert into a values (i_vc_name); 4 commit; 5 end proc; 6 / procedure created |
sql> exec proc('iii'); pl/sql procedure successfully completed sql> select * from a; col ---------------------------------------- iii sql> grant execute on proc to b; grant succeeded |
sql> conn b/b@sicsdb connected to oracle database 11g enterprise edition release 11.2.0.4.0 connected as b sql> exec proc('jjj'); pl/sql procedure successfully completed sql> select * from a; col ---------------------------------------- |
sql> conn a/a@sicsdb connected to oracle database 11g enterprise edition release 11.2.0.4.0 connected as a sql> sql> create or replace procedure proc(i_vc_name varchar2) authid current_user is 2 begin 3 insert into a values (i_vc_name); 4 commit; 5 end proc; 6 / procedure created |
sql> select * from v$version; banner -------------------------------------------------------------------------------- database 11g enterprise edition release 11.2.0.4.0 - 64bit production pl/sql release 11.2.0.4.0 - production core 11.2.0.4.0 production tns for 64-bit : version 11.2.0.4.0 - production nlsrtl version 11.2.0.4.0 – production 创建对应schema和数据表。 sql> create user a identified by a; user created sql> create user b identified by b; user created sql> grant connect, resource to a,b; grant succeeded sql> grant create procedure to a,b; grant succeeded sql> grant create synonym to a,b; grant succeeded |
sql> conn a/a@sicsdb connected to oracle database 11g enterprise edition release 11.2.0.4.0 connected as a sql> create table a(col varchar2(10)); table created sql> create or replace procedure proc(i_vc_name varchar2) is 2 begin 3 insert into a values (i_vc_name); 4 commit; 5 end proc; 6 / procedure created |
php code class excel{ var $header = " xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/tr/rec-html40">"; var $footer = ""; var $lines = array (); var $worksheet_title = "table1"; function addrow ($array) { $cells = ""; foreach ($array as $k => $v): if(is_numeric($v)) { if(substr($v, 0, 1) == 0) { $cells .= " } else { $cells .= " } } else { $cells .= " } endforeach; $this->lines[] = " unset($arry); } function setworksheettitle ($title) { $title = preg_replace ("/[\|:|/|?|*|[|]]/", "", $title); $title = substr ($title, 0, 31); $this->worksheet_title = $title; } function generatexml ($filename) { // deliver header (as recommended in php manual) header("content-type: application/vnd.ms-excel; charset=utf-8"); header("content-disposition: inline; filename="" . $filename . ".xls""); // print out document to the browser // need to use stripslashes for the damn ">" echo stripslashes ($this->header); echo "n echo " echo implode ("n", $this->lines); echo " echo $this->footer; exit; } function write ($filename) // 重点 { $content= stripslashes ($this->header); $content.= "n $content.= " $content.= implode ("n", $this->lines); $content.= " $content.= $this->footer;//excel文件 //error_log($content, 3,$filename); if (!file_exists($filename))//判断有没有文件 { fopen($filename,'a'); } $fp = fopen($filename,'a'); fwrite($fp, $content);//写入文件 fclose($fp); unset($this->lines);//清空内存中的数据 } } |
phpcode include_once"./include/class.excel.php";//调用excel类 require_once'./include/class.zipfile.php';//调用大包类 $xls=newexcel;//实例化 $w=explode("limit",$where_str);//把where $p=6000;//分页原理 $a=$ip_list_count/$p;//分页原理 if($ip_list_count%$p==0)//分页原理 else//分页原理 for($i=0;$i<=$a;$i )//循环写出 { $s=6000*$i; $ip=$_sg['db']->fetch_all("select*frommain_info".$w[0]."limit".$s.",".$p);//调用自己写的数据库(数据库培训数据库认证)方法,写出数组 $xls->addarray($ip);//调用excel类中addarray方法 xml1=$xls->write("./".$i.".xls");//调用excel类中write方法 unset($ip); unset($xml1); sleep(1); } |
select `province_name`, `city_name` from `phoneno_section` where substring(?, phoneno_section_len) = phoneno_section limit ? 咨询说where中使用substring函数不行,修改函数为left,语句为 select `province_name`, `city_name` from `conf_phoneno_section` where left(?, phoneno_section_len) = phoneno_section limit ? |
inoodb引擎 mysql> create table engine1(id int) engine=innodb partition by range(id)(partition po values less than(10)); query ok, 0 rows affected (0.01 sec) mrg_myisam引擎 mysql> create table engine2(id int) engine=mrg_myisam partition by range(id)(partition po values less than(10)); error 1572 (hy000): engine cannot be used in partitioned tables blackhole引擎 mysql> create table engine3(id int) engine=blackhole partition by range(id)(partition po values less than(10)); query ok, 0 rows affected (0.01 sec) csv引擎 mysql> create table engine4(id int) engine=csv partition by range(id)(partition po values less than(10)); error 1572 (hy000): engine cannot be used in partitioned tables memory引擎 mysql> create table engine5(id int) engine=memory partition by range(id)(partition po values less than(10)); query ok, 0 rows affected (0.01 sec) federated引擎 mysql> create table engine6(id int) engine=federated partition by range(id)(partition po values less than(10)); query ok, 0 rows affected (0.01 sec) archive引擎 mysql> create table engine7(id int) engine=archive partition by range(id)(partition po values less than(10)); query ok, 0 rows affected (0.01 sec) myisam 引擎 mysql> create table engine8(id int) engine=myisam partition by range(id)(partition po values less than(10)); query ok, 0 rows affected (0.01 sec) |
day() dayofmonth() dayofweek() dayofyear() datediff() extract() hour() microsecond() minute() mod() month() quarter() second() time_to_sec() to_days() weekday() year() yearweek() 等 |
create table ptime11(id int,createdate datetime) engine=myisam partition by range (day(createdate)) (partition po values less than (15),partition p1 values less than (31)); mysql> insert into ptime11 values (1,'2010-06-17'); mysql> explain partitions select count(1) from ptime11 where createdate>'2010-08-17'\g; *************************** 1. row *************************** id: 1 select_type: simple table: ptime11 partitions: po,p1 type: all possible_keys: null key: null key_len: null ref: null rows: 5 extra: using where 1 row in set (0.00 sec) |
public mydbcontext () :base("connectionstringorname") { } |
public mydbcontext(string connection) { database.connection.connectionstring = getsqlitestring(connection); } |
private string getsqlitestring(string connect) { return "data source=" connect; } |
class hello_vip_model_entity_vip_adapter extends mage_core_model_mysql4_abstract { protected $_logfile = 'vip.adapter.log'; protected function _construct() { $this->_setresource(array('read' =>'vip_space_read', 'write' =>'vip_space_read')); } |
create procedure getsum @n int =0<--此处为參数--> as declare @sum int<--定义变量--> declare @i int set @sum=0 set @i=0 while @i<=@n begin set @sum=@sum @i set @i=@i 1 end print 'the sum is ' ltrim(rtrim(str(@sum))) |
import java.sql.*; public class proceduretest { public static void main(string args[]) throws exception { //载入驱动 drivermanager.registerdriver(new sun.jdbc.odbc.jdbcodbcdriver()); //获得连接 connection conn=drivermanager.getconnection("jdbc:odbc:mydata","sa",""); //创建存储过程的对象 callablestatement c=conn.preparecall("{call getsum(?)}"); //给存储过程的參数设置值 c.setint(1,100); //将第一个參数的值设置成100 //运行存储过程 c.execute(); conn.close(); } } |
alter procedure getsum @n int =0, @result int output as declare @sum int declare @i int set @sum=0 set @i=0 while @i<=@n begin set @sum=@sum @i set @i=@i 1 end set @result=@sum |
import java.sql.*; public class proceduretest { public static void main(string args[]) throws exception { //载入驱动 drivermanager.registerdriver(new sun.jdbc.odbc.jdbcodbcdriver()); //获得连接 connection conn=drivermanager.getconnection("jdbc:odbc:mydata","sa",""); //创建存储过程的对象 callablestatement c=conn.preparecall("{call getsum(?,?)}"); //给存储过程的第一个參数设置值 c.setint(1,100); //注冊存储过程的第二个參数 c.registeroutparameter(2,java.sql.types.integer); //运行存储过程 c.execute(); //得到存储过程的输出參数值 system.out.println (c.getint(2)); conn.close(); } } |
import java.sql.*; public class proceduretest { public static void main(string args[]) throws exception { //载入驱动 drivermanager.registerdriver(new sun.jdbc.odbc.jdbcodbcdriver()); //获得连接 connection conn=drivermanager.getconnection("jdbc:odbc:mydata","sa",""); callablestatement c=conn.preparecall("{call cursorintoprocedure(?)}"); c.registeroutparameter(1,java.sql.types.varchar); c.execute(); system.out.println (c.getstring(1)); conn.close(); } } |
drop table 学生基本信息表 create table 学生基本信息表 ( stuid int primary key, stuname varchar(10), stuaddress varchar(20) ) insert into 学生基本信息表 values(1,'三毛','wuhan') insert into 学生基本信息表 values(2,'三毛','wuhan') create table 学生成绩表 ( stuid int, chinese int, pyhsics int foreign key(stuid) references 学生基本信息表(stuid) on delete cascade on update cascade ) insert into 学生成绩表 values(1,99,100) insert into 学生成绩表 values(2,99,100) |
import java.sql.*; public class proceduretest { public static void main(string args[]) throws exception { //载入驱动 drivermanager.registerdriver(new sun.jdbc.odbc.jdbcodbcdriver()); //获得连接 connection conn=drivermanager.getconnection("jdbc:odbc:mydata","sa",""); //创建存储过程的对象 callablestatement c=conn.preparecall("{call delepro(?)}"); c.setint(1,1); c.execute(); c=conn.preparecall("{call selepro}"); resultset rs=c.executequery(); while(rs.next()) { string stu=rs.getstring("stuid"); string name=rs.getstring("stuname"); string add=rs.getstring("stuaddress"); system.out.println ("学号:" " " "姓名:" " " "地址"); system.out.println (stu " " name " " add); } c.close(); } } |
import java.sql.*; public class proceduretest { public static void main(string args[]) throws exception { //载入驱动 drivermanager.registerdriver(new sun.jdbc.odbc.jdbcodbcdriver()); //获得连接 connection conn=drivermanager.getconnection("jdbc:odbc:mydata","sa",""); //创建存储过程的对象 callablestatement c=conn.preparecall("{call modpro(?,?)}"); c.setint(1,2); c.setstring(2,"美女"); c.execute(); c=conn.preparecall("{call selepro}"); resultset rs=c.executequery(); while(rs.next()) { string stu=rs.getstring("stuid"); string name=rs.getstring("stuname"); string add=rs.getstring("stuaddress"); system.out.println ("学号:" " " "姓名:" " " "地址"); system.out.println (stu " " name " " add); } c.close(); } } |
import java.sql.*; public class proceduretest { public static void main(string args[]) throws exception { //载入驱动 drivermanager.registerdriver(new sun.jdbc.odbc.jdbcodbcdriver()); //获得连接 connection conn=drivermanager.getconnection("jdbc:odbc:mydata","sa",""); //创建存储过程的对象 callablestatement c=conn.preparecall("{call findcusts(?)}"); c.setstring(1,"tom"); resultset rs=c.executequery(); while(rs.next()) { string cust=rs.getstring("customerid"); system.out.println (cust); } c.close(); } } |
import java.sql.*; public class proceduretest { public static void main(string args[]) throws exception { //载入驱动 drivermanager.registerdriver(new sun.jdbc.odbc.jdbcodbcdriver()); //获得连接 connection conn=drivermanager.getconnection("jdbc:odbc:mydata","sa",""); //创建存储过程的对象 callablestatement c=conn.preparecall("{call insertpro(?,?,?)}"); c.setint(1,6); c.setstring(2,"liu"); c.setstring(3,"wuhan"); c.execute(); c=conn.preparecall("{call selepro}"); resultset rs=c.executequery(); while(rs.next()) { string stuid=rs.getstring("stuid"); string name=rs.getstring("stuname"); string address=rs.getstring("stuaddress"); system.out.println (stuid " " name " " address); } c.close(); } } |
import java.sql.*; public class proceduretest { public static void main(string args[]) throws exception { //载入驱动 drivermanager.registerdriver(new sun.jdbc.odbc.jdbcodbcdriver()); //获得连接 connection conn=drivermanager.getconnection("jdbc:odbc:mydata","sa",""); statement stmt=conn.createstatement(); //在java中创建存储过程 stmt.executeupdate("create procedure oop as select * from 学生成绩表"); callablestatement c=conn.preparecall("{call oop}"); resultset rs=c.executequery(); while(rs.next()) { string chinese=rs.getstring("chinese"); system.out.println (chinese); } conn.close(); } } |
exec dbo.xp_readerrorlog --写0或null都会报错,直接运行即可 exec dbo.xp_readerrorlog 1 exec dbo.xp_readerrorlog 6 --sql server 2000 read error log if object_id('tempdb..#tmp_error_log_all') is not null drop table #tmp_error_log_all create table #tmp_error_log_all ( info varchar(8000),--datetime processinfo text num int ) insert into #tmp_error_log_all exec dbo.xp_readerrorlog --split error text if object_id('tempdb..#tmp_error_log_split') is not null drop table #tmp_error_log_split create table #tmp_error_log_split ( logdate datetime,--datetime processinfo varchar(100),--processinfo info varchar(7900)--text ) insert into #tmp_error_log_split select convert(datetime,left(info,22),120), left(stuff(info,1,23,''),charindex(' ',stuff(info,1,23,'')) - 1), ltrim(stuff(info,1,23 charindex(' ',stuff(info,1,23,'')),'')) from #tmp_error_log_all where isnumeric(left(info,4)) = 1 and info <> '.' and substring(info,11,1) = ' ' select * from #tmp_error_log_split where info like '456%' |
--sql server 2005 read error log if object_id('tempdb..#tmp_error_log') is not null drop table #tmp_error_log create table #tmp_error_log ( logdate datetime, processinfo varchar(100), info varchar(8000) ) insert into #tmp_error_log exec dbo.xp_readerrorlog select * from #tmp_error_log where info like '456%' |
declare @start_time datetime ,@end_time datetime set @start_time = convert(char(10),getdate() - 1,120) set @end_time = getdate() if object_id('tempdb..#tmp_error_log') is not null drop table #tmp_error_log create table #tmp_error_log ( logdate datetime, processinfo varchar(100), info varchar(8000) ) insert into #tmp_error_log exec dbo.xp_readerrorlog 0,1,null,null,@start_time,@end_time,n'desc' select count(1) as num, max(logdate) as logdate,info from #tmp_error_log where (info like '%error%' or info like '%warn%' or info like '�il%' or info like '%stop%') and info not like '%checkdb%' and info not like '%registry startup parameters%' and info not like '%logging sql server messages in file%' and info not like '%previous log for older entries%' group by info |
mysqlbinlog --raw --read-from-remote-server --stop-never
db2iadm1(db2inst1) db2fadm1( db2fenc1) [root@localhost expc]# groupadd -g 2000 db2iadm1 [root@localhost expc]# groupadd -g 2001 db2fadm1 [root@localhost expc]# useradd -m -g db2iadm1 -d /home/db2inst1 db2inst1 [root@localhost expc]# useradd -m -g db2fadm1 -d /home/db2fenc1 db2fenc1 [root@localhost expc]# passwd db2inst1 [root@localhost expc]# passwd db2fenc1 |
[root@localhost instance]# pwd /opt/ibm/db2/v10.1/instance [root@localhost instance]# chmod -r 775 * [root@localhost instance]# ./db2icrt -p 50000 -u db2fenc1 db2inst1 [root@localhost instance]# su - db2inst1 [db2inst1@localhost ~]$ db2sampl creating database "sample"... connecting to database "sample"... creating tables and data in schema "db2inst1"... creating tables with xml columns and xml data in schema "db2inst1"... 'db2sampl' processing complete. [db2inst1@localhost ~]$ db2start sql1026n the database manager is already active. [db2inst1@localhost ~]$ db2 connect to sample database connection information database = db2/linux 10.1.2 authorization id = db2inst1 local database alias = sample [db2inst1@localhost ~]$ db2 "select * from staff" |
[root@localhost expc]# groupadd -g 2002 db2asgrp [root@localhost expc]# useradd -m -g db2asgrp -d /home/db2as db2as [root@localhost expc]# passwd db2as [db2as@localhost ~]$ su - db2as # 这里测试新建用户 [db2as@localhost ~]$ su # 这里进入root权限 [root@localhost ~]# cd /opt/ibm/db2/v10.1/instance/ [root@localhost instance]# ./dascrt -u db2as dbi1070i program dascrt completed successfully. [root@localhost instance]# su - db2as [db2as@localhost ~]$ db2admin start sql4409w the db2 administration server is already active. |