Chinaunix首页 | 论坛 | 博客
  • 博客访问: 213350
  • 博文数量: 40
  • 博客积分: 316
  • 博客等级: 二等列兵
  • 技术积分: 840
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-13 12:39
文章分类

全部博文(40)

文章存档

2014年(2)

2013年(28)

2012年(10)

分类: Mysql/postgreSQL

2013-01-10 16:03:07

mysql备份
mysqldump -u root -p [mima] 数据库 -l -F '/tmp/test.sql'
reset master; 清空二进制日志文件。
show master status; 查看当前日志情况。
show master logs; 查看一共有多少bin日志。
flush logs; 清空日志缓存。
mysqlbinlog --no-defaults mysql-bin.000000002 | mysql -u root -p123 test.
//从binlog中回复数据。
mysqlbinlog --no-defaults --start-position="300" --stop-position="500" mysql-bin.00004 | mysql -uroot -p123 test  //回复binlog中从300到500的日志。
mysql -u root -p123 test -v -f
//回复日志。-f 遇到错误,skip过去,继续下一条。-v 查看详细导入信息。
grants for user1@192.168.1.1; 授权所有权限给这个用户。
show slave status\G; //slave_io_running: yes //此进程从主服务器上读取binlog日志,并写入从服务器上的中继日志中。     //slave_sql_running:yes //此进程负责读取并且执行中继日志中的binlog日志。

show plugins; //查看mysql当前插件。
show procedure status; //查看存储。

索引
alter table table_name add index index_name(column_list);
alter table table_name drop index index_name;//可删除唯一索引和一般索引,唯一索引是特殊的一般索引。

alter table table_name add [unique]/[primary key] (column_list);
alter table table_name drop primary key;
注:先删除自增,再删除索引。
alter table table_name modify column_list int unsigned not null; //绿色部分为创建时的语句,只是没有 自增。 // 删除自增。

函数
select concat("hello","world") as myname; //as可省略,myname是别名。
-------------------
   myname
------------
hello world
------------------//左边为输出结果。
lcase() ucase() length() ltrim()//左取空。 rtrim() repeat(str,count) bin()
replace(str,search_str,replace_str)
substr(str,position[,length]) //position从一开始
space() //生成空格。

bin()//十进制转二进制。max() min() sqrt() ceiling() floor() rand()

curdate() curtime() now() unix_timestamp() week() year() datediff(data1,data2)

mysql预处理:
prepare stmt1 from "select * from t1 where id>?";
set @i=1; //设置变量。
execute stmt1 using @i; //执行预处理。
drop prepare stmt1; //删除预处理。

事务:
set autocommit=0;//关闭自动提交。
rollback; //回滚。
commit;
savepoint p1;//保存一个还原点。
rollback to p1;

alter table t1 engine=innodb; //修改表引擎。
select @@autocommit; //显示autocommit的值。
truncate t1; //清空t1表。会把autoincrement 清除从1 开始。
select * from t1 union select * from t2;  //union 如果有重复的则 去重。
select * from t1 union all select * from t2; //union all ,即使有重复的也不去重。

触发器:
create trigger tg2 before insert on t1 for each row
->begin
->insert into t2 values(new.id);
->end      
//当t1 中插入时,t2 也插入。
show triggers\G;
drop triggers tg2; //删除tg2触发器。

重排auto_increment 值:
step 1. 清空表。
step 2. alter table table_name auto_increment=1;

mysql 帮助:
? contents;  
? %
? crea%
-----------------------------------------------------------------
mysql函数
sql>select substring('test',1,1);  当逗号不能使用时, 可以select substring('test' from 1 for 1);
-----------------------------------------------------------------
pentest相关:
->select load_file('/etc/passwd');        //有的4.x的版本可以用来找web root的路径。根据返回的不同来区分存在否。
----------
->create table temp(id text);    // 建表。
->load data infile '/etc/passwd'  into table  temp;       //有的5.x 的也可以用来找web root 的路径。 根据返回的不同区分存在否。
阅读(1744) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~