正在加载...
分页: 1/12 第一页 1 2 3 4 5 6 7 8 9 10 下页 最后页 [ 显示模式: 摘要 | 列表 ]

mysql分页limit 优化

[ 2011/06/27 15:29 | by selboo ]
mysql的分页比较简单,只需要limit offset,length就可以获取数据了,但是当offset和length比较大的时候,mysql明显性能下降

1.子查询优化法
先找出第一条数据,然后大于等于这条数据的id就是要获取的数据
缺点:数据必须是连续的,可以说不能有where条件,where条件会筛选数据,导致数据失去连续性

[codes=sql]mysql> set profiling=1;
Query OK, 0 rows affected (0.00 sec)

mysql> select count(*) from Member;
+----------+
| count(*) |
+----------+
|   169566 |
+----------+
1 row in set (0.00 sec)

mysql> pager grep
Tags: , , ,
From:http://salogs.com


由于业务需求,需要在现有mysql中安装sphinx的存储引擎,要保证现有mysql运行的情况下完成。mysql也的确支持存储引擎的在线热插拔,下面介绍安装步骤:

1、查看现有mysql的运行版本
# mysqladmin  -u user -ppwd version

Server version          5.1.47-log
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket           /data/mysql_db/mysql.sock
Uptime:                 15 days 2 hours 17 min 40 sec

Tags:

mysql Unknown command '''.

[ 2011/05/09 14:14 | by selboo ]
[root@db2 db]# mysql -uroot -p'123456' db_blog < 2011-05-08.db_blog.sql
PAGER set to stdout
ERROR at line 1058: Unknown command '\''.



修改为:
[root@db2 db]# mysql -uroot -p'123456' --default-character-set=gb2312 db_blog < 2011-05-08.db_blog.sql

则问题解决
这是由于导入和导出的两端的字符集不一致出现的问题 导致。

非常实用的sql语句

[ 2010/09/17 15:15 | by selboo ]
1、说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用)
select * into b from a where 1 <> 1
select top 0 * into b from a

2、说明:拷贝表(拷贝数据,源表名:a 目标表名:b) (Access可用)
insert into b(a, b, c) select d,e,f from b;

3、说明:跨数据库之间表的拷贝(具体数据使用绝对路径) (Access可用)
[code]insert into b(a, b, c) select d,e,f from b in ‘具体数据库’ where 条件
例子:..from b in ' "&Server.MapPath( ". ")& "\data.mdb " & " ' where.. <
Tags: ,

每天MySQL自动优化

[ 2010/08/04 18:41 | by selboo ]
[root@74-82-173-217 ~]# mysqlcheck -Aao --auto-repair -uroot -p'*********'


下面说下几个参数的含义

-a, --analyze 分析 [Analyze given tables]
-o, --optimize 优化 [Optimize table]
-A, --all-databases 所有的数据库 [Check all the database]
--auto-repair 自动修复 [If a checked table is corrupted, automatically fix it. Repairing will be done after all tables have been checked, if corrupted ones were found]


加入 cronjob
分页: 1/12 第一页 1 2 3 4 5 6 7 8 9 10 下页 最后页 [ 显示模式: 摘要 | 列表 ]