127.0.0.1:6370> mset a 1 b 2 c 3 d 4 e 5 f 6
OK
127.0.0.1:6370> RANDOMKEY
"a"
127.0.0.1:6370> RANDOMKEY
"f"
127.0.0.1:6370> RANDOMKEY
"e"
127.0.0.1:6370> RANDOMKEY
"a"
遍历获取键值
一般情况下,我们会使用keys PATTERN来查找匹配的键值。但是,如果数据量很大,keys操作会很消耗系统资源,stop the world的事情不是我们想看到的!此时,可以通过scan/hscan/zscan/ssan命令依次获取。
获取库中的键值
123
127.0.0.1:6370> eval "for i=1,100000 do redis.call('set', 'a' .. i, i) end" 0
(nil)
(0.98s)
Basically with COUNT the user specified the amount of work that should be done at every call in order to retrieve elements from the collection. This is just an hint for the implementation, however generally speaking this is what you could expect most of the times from the implementation.
3、InnoDB采用表空间(tablespace)来管理数据,存储表数据和索引,
InnoDB数据库文件(即InnoDB文件集,ib-file set):
ibdata1、ibdata2等:系统表空间文件,存储InnoDB系统信息和用户数据库表数据和索引,所有表共用
.ibd文件:单表表空间文件,每个表使用一个表空间文件(file per table),存放用户数据库表数据和索引
日志文件: ib_logfile1、ib_logfile2
12345678910
create database hello;
use hello;
create table abc ( name varchar(1000), age int );
insert into abc values ("1", 1);
create table abc_myisam ( name varchar(100), age int ) engine=myisam;
insert into abc_myisam values ( '1', 1), ('2',2);
alter table abc_myisam partition by hash(age) partitions 4 ;
insert into abc_myisam values ( '11', 10), ('2',20), ( '1', 11), ('2',21), ( '1', 21), ('2',22), ( '1', 31), ('2',32), ( '1', 41), ('2',24), ( '1', 15), ('2',23) ;
最终库目录如下:
根据月份来进行分区:
123456789101112
--最好按照月份分区(date需要为日期类型)
alter table abc_myisam PARTITION BY RANGE (extract(YEAR_MONTH from date)) (
PARTITION p410 VALUES LESS THAN (201411),
PARTITION p411 VALUES LESS THAN (201412),
PARTITION p412 VALUES LESS THAN (201501),
PARTITION p501 VALUES LESS THAN (201502),
PARTITION p502 VALUES LESS THAN (201503),
PARTITION p503 VALUES LESS THAN (201504),
PARTITION p504 VALUES LESS THAN (201505),
PARTITION p505 VALUES LESS THAN (201506),
PARTITION p0 VALUES LESS THAN MAXVALUE
)
根据日期来分区:
1234567
alter table t_dta_activeresources_ip PARTITION BY RANGE (to_days(day)) (
PARTITION p0 VALUES LESS THAN (735926),
PARTITION p141124 VALUES LESS THAN (735927),
PARTITION p141125 VALUES LESS THAN (735928),
PARTITION p141126 VALUES LESS THAN (735929),
PARTITION p88 VALUES LESS THAN MAXVALUE
)
查询时执行计划带上partitions可以查看命中的是那个分区:
12345678910111213141516
mysql> explain select * from t_dta_illegalweb where day='2015-01-04';
+----+-------------+------------------+------+---------------+------+---------+------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------------+------+---------------+------+---------+------+---------+-------------+
| 1 | SIMPLE | t_dta_illegalweb | ALL | NULL | NULL | NULL | NULL | 1335432 | Using where |
+----+-------------+------------------+------+---------------+------+---------+------+---------+-------------+
1 row in set
mysql> explain partitions
select * from t_dta_illegalweb where day='2015-01-04';
+----+-------------+------------------+------------+------+---------------+------+---------+------+---------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------------+------------+------+---------------+------+---------+------+---------+-------------+
| 1 | SIMPLE | t_dta_illegalweb | p150104 | ALL | NULL | NULL | NULL | NULL | 1335432 | Using where |
+----+-------------+------------------+------------+------+---------------+------+---------+------+---------+-------------+
1 row in set
如果清理掉分区的数据后,再查看执行计划:
12345678910
mysql> alter table t_dta_illegalweb truncate partition p150104;
Query OK, 0 rows affected
mysql> explain partitions select * from t_dta_illegalweb where day='2015-01-04';
+----+-------------+-------+------------+------+---------------+------+---------+------+------+-----------------------------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+-----------------------------------------------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Impossible WHERE noticed after reading const tables |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+-----------------------------------------------------+
1 row in set
yum install nginx
less /etc/nginx/nginx.conf
less /etc/nginx/conf.d/default.conf
service nginx restart
实际操作中没有root,只能自己编译了:
123456789
下载nginx,pcre-8.36.zip,zlib-1.2.3.tar.gz解压到src下。
cd nginx-1.7.7
./configure --prefix=/home/omc/tools/nginx --with-pcre=src/pcre --with-zlib=src/zlib
make && make install
cd /home/omc/tools/nginx
vi conf/nginx.conf # 修改listen的端口,80要root才能起
sbin/nginx
sbin/nginx -s reload
如果编译的目录和真正存放程序的路径不一致时,可以使用-p参数来指定。
123
cd nginx
sbin/nginx -p $PWD
sbin/nginx -s reload -p $PWD